Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni via buildroot <buildroot@buildroot.org>
To: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Cc: buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH 1/1] package/sdl2_mixer: force arm mode instead of Thumb mode
Date: Mon, 5 Feb 2024 22:45:47 +0100	[thread overview]
Message-ID: <20240205224547.5435732c@windsurf> (raw)
In-Reply-To: <20240109214953.724112-1-fontaine.fabrice@gmail.com>

Hello Fabrice,

On Tue,  9 Jan 2024 22:49:53 +0100
Fabrice Fontaine <fontaine.fabrice@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
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

      reply	other threads:[~2024-02-05 21:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 21:49 [Buildroot] [PATCH 1/1] package/sdl2_mixer: force arm mode instead of Thumb mode Fabrice Fontaine
2024-02-05 21:45 ` Thomas Petazzoni via buildroot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240205224547.5435732c@windsurf \
    --to=buildroot@buildroot.org \
    --cc=fontaine.fabrice@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox