JustasMasiulis / xorstr

heavily vectorized c++17 compile time string encryption.
Apache License 2.0
1.19k stars 193 forks source link

Support x86/x86_64 for Android emulator #56

Closed AndroidMaster24 closed 1 year ago

AndroidMaster24 commented 1 year ago

The app crashes when using xorstr without avx support on x86 lib for Android emulator. Can you add x86/x86_64 support for Android platform? image

ghost commented 1 year ago

x86 support would be nice because i'm adding x86 support for emulator compatibilty. I wonder what instruction Android is using

Here is CPU info (Ignore CPU cores because I configured like that)

64-bit image

32-bit image

JustasMasiulis commented 1 year ago

Hey, so what exact instruction is it crashing on?

Currently when AVX support is disabled, SSE2 instructions are used (pxor, movdqa).

If SSE2 is no-go, but SSE is OK, it should be pretty trivial to change this piece of code:

        ((Indices >= sizeof(_storage) / 16 ? static_cast<void>(0) : _mm_store_si128(
            reinterpret_cast<__m128i*>(_storage) + Indices,
            _mm_xor_si128(_mm_load_si128(reinterpret_cast<const __m128i*>(_storage) + Indices),
                          _mm_load_si128(reinterpret_cast<const __m128i*>(keys) + Indices)))), ...);

to use _mm_store_ps, _mm_load_ps and _mm_xor_ps, which should be functionally equivalent, but use the __m128 type instead (packed floats instead of integers) and only require SSE.

JustasMasiulis commented 1 year ago

Here is CPU info (Ignore CPU cores because I configured like that)

Assuming it supported everything a Silvermont generation CPU should, SSE and SSE2 shouldn't cause any problems. Are you sure that AVX was for sure disabled?

AndroidMaster24 commented 1 year ago

Nevermind, it was an issue with const char* const, I implemented it other way to make it work. Xorstr works perfectly fine on both x86 and x86_64 emulators

@BoomboomDada Emulator using fake CPU info, so the info in AIDA64 are not accurate. Use cat /proc/cpuinfo in terminal.

image

Emulator using CPU passthrough so it supports AVX directly but the compiler doesn't support AVX, therefore #define JM_XORSTR_DISABLE_AVX_INTRINSICS is mandatory