From 7e7f8b295f2996bf47211e57526ff19cc93d3d56 Mon Sep 17 00:00:00 2001 From: Lai Wei-Chih Date: Wed, 15 May 2013 20:52:00 +0800 Subject: [PATCH] Implement optimized __swap16md and __swap32md. --- ndk/sources/android/libportable/Android.mk | 9 +++-- .../android/libportable/arch-arm/md_swap.c | 40 +++++++++++++++++++ .../android/libportable/arch-mips/md_swap.c | 38 ++++++++++++++++++ .../android/libportable/arch-x86/md_swap.c | 31 ++++++++++++++ 4 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 ndk/sources/android/libportable/arch-arm/md_swap.c create mode 100644 ndk/sources/android/libportable/arch-mips/md_swap.c create mode 100644 ndk/sources/android/libportable/arch-x86/md_swap.c diff --git a/ndk/sources/android/libportable/Android.mk b/ndk/sources/android/libportable/Android.mk index 63428e5cb..dde8e1961 100644 --- a/ndk/sources/android/libportable/Android.mk +++ b/ndk/sources/android/libportable/Android.mk @@ -57,7 +57,8 @@ libportable_arch_src_files += \ arch-mips/timer.c \ arch-mips/timerfd.c \ arch-mips/waitpid.c \ - arch-mips/fenv.c + arch-mips/fenv.c \ + arch-mips/md_swap.c libportable_arch_src_files += \ arch-mips/_setjmp.S \ @@ -69,7 +70,8 @@ endif ifeq ($(TARGET_ARCH),arm) libportable_arch_src_files += \ arch-arm/unwind.c \ - arch-arm/fenv.c + arch-arm/fenv.c \ + arch-arm/md_swap.c endif ifeq ($(TARGET_ARCH),x86) @@ -79,7 +81,8 @@ libportable_arch_src_files += \ arch-x86/ioctl.c \ arch-x86/open.c \ arch-x86/stat.c \ - arch-x86/fenv.c + arch-x86/fenv.c \ + arch-x86/md_swap.c endif LOCAL_SRC_FILES := \ diff --git a/ndk/sources/android/libportable/arch-arm/md_swap.c b/ndk/sources/android/libportable/arch-arm/md_swap.c new file mode 100644 index 000000000..47652e6cc --- /dev/null +++ b/ndk/sources/android/libportable/arch-arm/md_swap.c @@ -0,0 +1,40 @@ +/* + * Copyright 2013, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +/* + * REV and REV16 weren't available on ARM5 or ARM4. + */ +#if !defined __ARM_ARCH_5__ && !defined __ARM_ARCH_5T__ && \ + !defined __ARM_ARCH_5TE__ && !defined __ARM_ARCH_5TEJ__ && \ + !defined __ARM_ARCH_4T__ && !defined __ARM_ARCH_4__ + +uint16_t WRAP(__swap16md)(uint16_t x) { + register uint16_t _x = (x); + __asm volatile ("rev16 %0, %0" : "+l" (_x)); + return _x; +} + +uint32_t WRAP(__swap32md)(uint32_t x) { + register uint32_t _x = (x); + __asm volatile ("rev %0, %0" : "+l" (_x)); + return _x; +} + +#endif + diff --git a/ndk/sources/android/libportable/arch-mips/md_swap.c b/ndk/sources/android/libportable/arch-mips/md_swap.c new file mode 100644 index 000000000..59e422470 --- /dev/null +++ b/ndk/sources/android/libportable/arch-mips/md_swap.c @@ -0,0 +1,38 @@ +/* + * Copyright 2013, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#if defined(__mips_isa_rev) && (__mips_isa_rev >= 2) + +uint16_t WRAP(__swap16md)(uint16_t x) { + register uint16_t _x = x; + register uint16_t _r; + __asm volatile ("wsbh %0, %1" : "=r" (_r) : "r" (_x)); + return _r; +} + +uint32_t WRAP(__swap32md)(uint32_t x) { + register uint32_t _x = x; + register uint32_t _r; + __asm volatile ("wsbh %0, %1; rotr %0, %0, 16" : "=r" (_r) : "r" (_x)); + return _r; +} + +#endif + diff --git a/ndk/sources/android/libportable/arch-x86/md_swap.c b/ndk/sources/android/libportable/arch-x86/md_swap.c new file mode 100644 index 000000000..60851d0ae --- /dev/null +++ b/ndk/sources/android/libportable/arch-x86/md_swap.c @@ -0,0 +1,31 @@ +/* + * Copyright 2013, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +uint16_t WRAP(__swap16md)(uint16_t x) { + register uint16_t _x = (x); + __asm volatile ("rorw $8, %w0" : "+r" (_x)); + return _x; +} + +uint32_t WRAP(__swap32md)(uint32_t x) { + register uint32_t _x = (x); + __asm volatile ("bswap %0" : "+r" (_x)); + return _x; +} +