[Buildroot] [PATCH 1/1] package/sdl2_mixer: force arm mode instead of Thumb mode
Thomas Petazzoni
thomas.petazzoni at bootlin.com
Mon Feb 5 21:45:47 UTC 2024
Hello Fabrice,
On Tue, 9 Jan 2024 22:49:53 +0100
Fabrice Fontaine <fontaine.fabrice at gmail.com> wrote:
> +# sdl2_mixer has some assembly function that is not present in Thumb mode:
> +# Error: selected processor does not support `clz r2,r3' in Thumb mode
> +# so, we desactivate Thumb mode
> +ifeq ($(BR2_ARM_INSTRUCTIONS_THUMB),y)
> +SDL2_MIXER_CONF_ENV += CFLAGS="$(TARGET_CFLAGS) -marm"
> +endif
Thanks a lot for working on this! However, I think this is not the best
fix. Indeed, instead we should patch the sdl2_mixer code so that it
only uses the optimized ARM implementation when it makes sense. The
code goes like this:
#if defined(__GNUC__) || defined(__clang__)
#if defined(DRFLAC_X64)
/* OPTIMIZED x86-64 code here */
#elif defined(DRFLAC_X86)
/* OPTIMIZED i386 code here */
/* This condition is the one that should be changed to exclude using this code on Thumb */
#elif defined(DRFLAC_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 5) && !defined(DRFLAC_64BIT) /* <-- I haven't tested 64-bit inline assembly, so only enabling this for the 32-bit build for now. */
{
unsigned int r;
__asm__ __volatile__ (
#if defined(DRFLAC_64BIT)
"clz %w[out], %w[in]" : [out]"=r"(r) : [in]"r"(x) /* <-- This is untested. If someone in the community could test this, that would be appreciated! */
#else
"clz %[out], %[in]" : [out]"=r"(r) : [in]"r"(x)
#endif
);
return r;
}
#else
/* And so we will fallback here, the "unoptimized" implementation */
if (x == 0) {
return sizeof(x)*8;
}
#ifdef DRFLAC_64BIT
return (drflac_uint32)__builtin_clzll((drflac_uint64)x);
#else
return (drflac_uint32)__builtin_clzl((drflac_uint32)x);
#endif
#endif
You can use some gcc internal macro to detect if we're building for
Thumb or not. Could you have a look in this direction?
Thanks a lot in advance!
Thomas
--
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
More information about the buildroot
mailing list