diff options
author | Balaram Makam <b.makam@samsung.com> | 2019-09-23 14:38:40 -0500 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-12-11 19:06:53 +0200 |
commit | f21a5b97f8d849c074f82ee7f7ea70ab2285d8bc (patch) | |
tree | 1aa6bb10333bd2222b9fcbfc36bce878e9cc2483 | |
parent | 46d54b22a21a551da6e4d8710527eb8f135c5e6a (diff) | |
download | android_bionic-f21a5b97f8d849c074f82ee7f7ea70ab2285d8bc.tar.gz android_bionic-f21a5b97f8d849c074f82ee7f7ea70ab2285d8bc.tar.bz2 android_bionic-f21a5b97f8d849c074f82ee7f7ea70ab2285d8bc.zip |
ASCII fastpath for towupper and towlower.
This change elides unnecessary calls to __find_icu_symbol
for ASCII chars and improves PUBG mobile game loading time by 7% on
hikey620(Cortex-A53):
name old time/op new time/op delta
PUBG_0.13.0_Launch 41.5s ± 2% 37.7s ± 3% -9.24% (p=0.008 n=5+5)
Below are the bionic benchmark results on a Pixel 2 XL for 64-bit,
showing a large speedup for ASCII and only a small slowdown for non-ASCII.
Before:
BM_wctype_towlower_ascii_n 10.5 ns 10.4 ns 61973065
BM_wctype_towlower_ascii_y 10.2 ns 10.2 ns 70158659
BM_wctype_towlower_unicode_n 10.3 ns 10.3 ns 67719478
BM_wctype_towlower_unicode_y 10.6 ns 10.5 ns 67841545
BM_wctype_towupper_ascii_n 10.8 ns 10.8 ns 63456778
BM_wctype_towupper_ascii_y 10.9 ns 10.9 ns 65116910
BM_wctype_towupper_unicode_n 10.7 ns 10.7 ns 67463276
BM_wctype_towupper_unicode_y 10.4 ns 10.4 ns 66467890
After:
BM_wctype_towlower_ascii_n 3.35 ns 3.34 ns 205567652
BM_wctype_towlower_ascii_y 3.30 ns 3.29 ns 214108746
BM_wctype_towlower_unicode_n 10.9 ns 10.8 ns 65007743
BM_wctype_towlower_unicode_y 10.6 ns 10.6 ns 63819060
BM_wctype_towupper_ascii_n 3.53 ns 3.53 ns 195944444
BM_wctype_towupper_ascii_y 3.48 ns 3.48 ns 199233248
BM_wctype_towupper_unicode_n 11.1 ns 11.1 ns 62760216
BM_wctype_towupper_unicode_y 11.0 ns 11.0 ns 61608872
Test: bionic unit tests on device
Test: bionic benchmarks on device
Signed-off-by: Balaram Makam <b.makam@samsung.com>
Change-Id: I77ab7efb66d7bcb35d00467663607535e5c1992f
-rw-r--r-- | libc/bionic/wctype.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libc/bionic/wctype.cpp b/libc/bionic/wctype.cpp index 6e33b6c51..061f55a90 100644 --- a/libc/bionic/wctype.cpp +++ b/libc/bionic/wctype.cpp @@ -117,12 +117,22 @@ int iswctype_l(wint_t wc, wctype_t char_class, locale_t) { } wint_t towlower(wint_t wc) { + if (wc < 0x80) { + if (wc >= 'A' && wc <= 'Z') return wc | 0x20; + return wc; + } + typedef UChar32 (*FnT)(UChar32); static auto u_tolower = reinterpret_cast<FnT>(__find_icu_symbol("u_tolower")); return u_tolower ? u_tolower(wc) : tolower(wc); } wint_t towupper(wint_t wc) { + if (wc < 0x80) { + if (wc >= 'a' && wc <= 'z') return wc & 0xdf; + return wc; + } + typedef UChar32 (*FnT)(UChar32); static auto u_toupper = reinterpret_cast<FnT>(__find_icu_symbol("u_toupper")); return u_toupper ? u_toupper(wc) : toupper(wc); |