From 8e4aa941c8ea7d9d7155e3f691a5935aee3161d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 28 Oct 2026 16:22:27 -0700 Subject: [PATCH] Added Android memoryMap, DirectoryReader, process memory, and NEON signbitsmask. (#479) --- include/bx/inline/simd128_neon.inl | 23 +++++++++++++++++++++-- src/file.cpp | 2 +- src/os.cpp | 16 +++++++--------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/bx/inline/simd128_neon.inl b/include/bx/inline/simd128_neon.inl index 9eacf3ad..66c3eabc 100644 --- a/include/bx/inline/simd128_neon.inl +++ b/include/bx/inline/simd128_neon.inl @@ -987,13 +987,32 @@ namespace bx template<> BX_SIMD_FORCE_INLINE int simd128_x32_signbitsmask(simd128_neon_t _a) { - return simd_x32_signbitsmask_ni(_a); + const uint32x4_t a = vreinterpretq_u32_f32(_a); + const uint32x4_t msb = vshrq_n_u32(a, 31); + const int32x2_t shiftLo = vcreate_s32(UINT64_C(0x0000000100000000) ); + const int32x2_t shiftHi = vcreate_s32(UINT64_C(0x0000000300000002) ); + const int32x4_t shift = vcombine_s32(shiftLo, shiftHi); + const uint32x4_t bits = vshlq_u32(msb, shift); + const uint64x2_t sum = vpaddlq_u32(bits); + const uint64_t lo = vgetq_lane_u64(sum, 0); + const uint64_t hi = vgetq_lane_u64(sum, 1); + return int(lo | hi); } template<> BX_SIMD_FORCE_INLINE int simd128_x8_signbitsmask(simd128_neon_t _a) { - return simd_x8_signbitsmask_ni(_a); + const uint8x16_t a = vreinterpretq_u8_f32(_a); + const uint8x16_t msb = vshrq_n_u8(a, 7); + const int8x8_t shiftLo = vcreate_s8(UINT64_C(0x0706050403020100) ); + const int8x16_t shift = vcombine_s8(shiftLo, shiftLo); + const uint8x16_t bits = vshlq_u8(msb, shift); + const uint16x8_t sum16 = vpaddlq_u8(bits); + const uint32x4_t sum32 = vpaddlq_u16(sum16); + const uint64x2_t sum64 = vpaddlq_u32(sum32); + const uint64_t lo = vgetq_lane_u64(sum64, 0); + const uint64_t hi = vgetq_lane_u64(sum64, 1); + return int(lo | (hi << 8) ); } template<> diff --git a/src/file.cpp b/src/file.cpp index 2273446d..8c60e096 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -12,7 +12,7 @@ #endif // BX_CONFIG_CRT_FILE_READER_WRITER #ifndef BX_CONFIG_CRT_DIRECTORY_READER -# define BX_CONFIG_CRT_DIRECTORY_READER (BX_PLATFORM_OS_DESKTOP && !BX_CRT_NONE) +# define BX_CONFIG_CRT_DIRECTORY_READER ( (BX_PLATFORM_OS_DESKTOP || BX_PLATFORM_ANDROID) && !BX_CRT_NONE) #endif // BX_CONFIG_CRT_DIRECTORY_READER #if BX_CRT_NONE diff --git a/src/os.cpp b/src/os.cpp index fe834a04..e68189a4 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -34,7 +34,8 @@ # endif // !BX_PLATFORM_PS4 && !BX_PLATFORM_PS5 # if BX_PLATFORM_ANDROID -# include // mallinfo +# include // fopen +# include # elif BX_PLATFORM_LINUX \ || BX_PLATFORM_RPI # include // fopen @@ -157,10 +158,7 @@ namespace bx size_t getProcessMemoryUsed() { -#if BX_PLATFORM_ANDROID - struct mallinfo mi = mallinfo(); - return mi.uordblks; -#elif BX_PLATFORM_LINUX +#if BX_PLATFORM_ANDROID || BX_PLATFORM_LINUX FILE* file = fopen("/proc/self/statm", "r"); if (NULL == file) { @@ -504,7 +502,7 @@ namespace bx namespace { -#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX +#if BX_PLATFORM_ANDROID || BX_PLATFORM_LINUX || BX_PLATFORM_OSX static int32_t toPosixProt(uint32_t _protect) { switch (_protect) @@ -557,7 +555,7 @@ namespace bx BX_ASSERT(_alignment <= granularity, "Alignments greater than the allocation granularity are not implemented (requested %zu, granularity %zu).", _alignment, granularity); BX_UNUSED(_alignment, granularity); -#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX +#if BX_PLATFORM_ANDROID || BX_PLATFORM_LINUX || BX_PLATFORM_OSX if (NULL == _address) { if (0 == (state & Memory::Reserve) ) @@ -737,7 +735,7 @@ namespace bx { BX_ERROR_SCOPE(_err); -#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX +#if BX_PLATFORM_ANDROID || BX_PLATFORM_LINUX || BX_PLATFORM_OSX int32_t result = munmap(_address, _size); if (-1 == result) @@ -768,7 +766,7 @@ namespace bx { const uint32_t page = _flags & Memory::PageMask; -#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX +#if BX_PLATFORM_ANDROID || BX_PLATFORM_LINUX || BX_PLATFORM_OSX if (0 != (page & Memory::PageHuge) ) { return 1ull << 30; // 1 GiB nominal