* [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time
@ 2019-12-02 15:58 Geert Uytterhoeven
2019-12-02 17:38 ` Eugeniu Rosca
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2019-12-02 15:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Kuninori Morimoto, Eugeniu Rosca, Nilkanth Ahirrao
Cc: alsa-devel, linux-renesas-soc, Geert Uytterhoeven
There is no need to store the inverted DALIGN values in the table, as
they can easily be calculated at run-time. This also protects against
the introduction of inconsistencies between normal and inverted values
by a future table modification.
Reorder the two subexpressions in the AND check, to perform the least
expensive check first.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Compile-tested only.
Interestingly, this decreases code size on arm64, but increases on arm32
(both gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)).
arm32:
text data bss dec hex filename
16186 276 84 16546 40a2 sound/soc/sh/rcar/core.o.orig
16194 276 84 16554 40aa sound/soc/sh/rcar/core.o
arm64:
text data bss dec hex filename
17426 392 104 17922 4602 sound/soc/sh/rcar/core.o.orig
17414 392 104 17910 45f6 sound/soc/sh/rcar/core.o
---
sound/soc/sh/rcar/core.c | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 399dc6e9bde5b042..d20f03dfdee66643 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -376,20 +376,15 @@ u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
*/
u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
{
- static const u32 dalign_values[8][2] = {
- {0x76543210, 0x67452301},
- {0x00000032, 0x00000023},
- {0x00007654, 0x00006745},
- {0x00000076, 0x00000067},
- {0xfedcba98, 0xefcdab89},
- {0x000000ba, 0x000000ab},
- {0x0000fedc, 0x0000efcd},
- {0x000000fe, 0x000000ef},
+ static const u32 dalign_values[8] = {
+ 0x76543210, 0x00000032, 0x00007654, 0x00000076,
+ 0xfedcba98, 0x000000ba, 0x0000fedc, 0x000000fe,
};
- int id = 0, inv;
+ int id = 0;
struct rsnd_mod *ssiu = rsnd_io_to_mod_ssiu(io);
struct rsnd_mod *target;
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
+ u32 dalign;
/*
* *Hardware* L/R and *Software* L/R are inverted for 16bit data.
@@ -425,15 +420,15 @@ u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
if (mod == ssiu)
id = rsnd_mod_id_sub(mod);
- /* Non target mod or non 16bit needs normal DALIGN */
- if ((snd_pcm_format_width(runtime->format) != 16) ||
- (mod != target))
- inv = 0;
- /* Target mod needs inverted DALIGN when 16bit */
- else
- inv = 1;
+ dalign = dalign_values[id];
+
+ if (mod == target && snd_pcm_format_width(runtime->format) == 16) {
+ /* Target mod needs inverted DALIGN when 16bit */
+ dalign = (dalign & 0xf0f0f0f0) >> 4 |
+ (dalign & 0x0f0f0f0f) << 4;
+ }
- return dalign_values[id][inv];
+ return dalign;
}
u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time
2019-12-02 15:58 [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time Geert Uytterhoeven
@ 2019-12-02 17:38 ` Eugeniu Rosca
2019-12-03 0:41 ` Kuninori Morimoto
2019-12-09 18:59 ` Applied "ASoC: rsnd: Calculate DALIGN inversion at run-time" to the asoc tree Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Eugeniu Rosca @ 2019-12-02 17:38 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Kuninori Morimoto, Nilkanth Ahirrao, alsa-devel,
linux-renesas-soc, Eugeniu Rosca, Eugeniu Rosca
Hi Geert,
On Mon, Dec 02, 2019 at 04:58:34PM +0100, Geert Uytterhoeven wrote:
> There is no need to store the inverted DALIGN values in the table, as
> they can easily be calculated at run-time. This also protects against
> the introduction of inconsistencies between normal and inverted values
> by a future table modification.
>
> Reorder the two subexpressions in the AND check, to perform the least
> expensive check first.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> ---
> Compile-tested only.
>
> Interestingly, this decreases code size on arm64, but increases on arm32
> (both gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)).
>
> arm32:
>
> text data bss dec hex filename
> 16186 276 84 16546 40a2 sound/soc/sh/rcar/core.o.orig
> 16194 276 84 16554 40aa sound/soc/sh/rcar/core.o
>
> arm64:
>
> text data bss dec hex filename
> 17426 392 104 17922 4602 sound/soc/sh/rcar/core.o.orig
> 17414 392 104 17910 45f6 sound/soc/sh/rcar/core.o
> ---
> sound/soc/sh/rcar/core.c | 31 +++++++++++++------------------
jFTR, using ARM's aarch64 gcc-8.3-2019.03 and v5.4-10271-g596cf45cbf6e:
$ size sound/soc/sh/rcar/core.o.before sound/soc/sh/rcar/core.o.after
text data bss dec hex filename
21433 380 88 21901 558d sound/soc/sh/rcar/core.o.before
21505 380 88 21973 55d5 sound/soc/sh/rcar/core.o.after
> 1 file changed, 13 insertions(+), 18 deletions(-)
>
> diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
> index 399dc6e9bde5b042..d20f03dfdee66643 100644
> --- a/sound/soc/sh/rcar/core.c
> +++ b/sound/soc/sh/rcar/core.c
> @@ -376,20 +376,15 @@ u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
> */
> u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
> {
> - static const u32 dalign_values[8][2] = {
> - {0x76543210, 0x67452301},
> - {0x00000032, 0x00000023},
> - {0x00007654, 0x00006745},
> - {0x00000076, 0x00000067},
> - {0xfedcba98, 0xefcdab89},
> - {0x000000ba, 0x000000ab},
> - {0x0000fedc, 0x0000efcd},
> - {0x000000fe, 0x000000ef},
> + static const u32 dalign_values[8] = {
> + 0x76543210, 0x00000032, 0x00007654, 0x00000076,
> + 0xfedcba98, 0x000000ba, 0x0000fedc, 0x000000fe,
FWIW, using below test procedure, I can reconstruct the original
two-dimensional dalign_values[8][2] array on the host:
#include <stdio.h>
#include <stdint.h>
typedef uint32_t u32;
void main(void)
{
u32 dalign, i;
static const u32 dalign_values[8] = {
0x76543210, 0x00000032, 0x00007654, 0x00000076,
0xfedcba98, 0x000000ba, 0x0000fedc, 0x000000fe,
};
for (i = 0; i < 8; i++) {
u32 keep = dalign = dalign_values[i];
dalign = (dalign & 0xf0f0f0f0) >> 4 |
(dalign & 0x0f0f0f0f) << 4;
printf("{0x%08x, 0x%08x},\n", keep, dalign);
}
}
--
Best Regards,
Eugeniu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time
2019-12-02 15:58 [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time Geert Uytterhoeven
2019-12-02 17:38 ` Eugeniu Rosca
@ 2019-12-03 0:41 ` Kuninori Morimoto
2019-12-09 18:59 ` Applied "ASoC: rsnd: Calculate DALIGN inversion at run-time" to the asoc tree Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Kuninori Morimoto @ 2019-12-03 0:41 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Eugeniu Rosca, Nilkanth Ahirrao, alsa-devel, linux-renesas-soc
Hi
> There is no need to store the inverted DALIGN values in the table, as
> they can easily be calculated at run-time. This also protects against
> the introduction of inconsistencies between normal and inverted values
> by a future table modification.
>
> Reorder the two subexpressions in the AND check, to perform the least
> expensive check first.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Applied "ASoC: rsnd: Calculate DALIGN inversion at run-time" to the asoc tree
2019-12-02 15:58 [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time Geert Uytterhoeven
2019-12-02 17:38 ` Eugeniu Rosca
2019-12-03 0:41 ` Kuninori Morimoto
@ 2019-12-09 18:59 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2019-12-09 18:59 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: alsa-devel, Eugeniu Rosca, Jaroslav Kysela, Kuninori Morimoto,
Liam Girdwood, linux-renesas-soc, Mark Brown, Nilkanth Ahirrao,
Takashi Iwai
The patch
ASoC: rsnd: Calculate DALIGN inversion at run-time
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.6
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
From 49df1e3925824cf44e590daac635974270185841 Mon Sep 17 00:00:00 2001
From: Geert Uytterhoeven <geert+renesas@glider.be>
Date: Mon, 2 Dec 2019 16:58:34 +0100
Subject: [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time
There is no need to store the inverted DALIGN values in the table, as
they can easily be calculated at run-time. This also protects against
the introduction of inconsistencies between normal and inverted values
by a future table modification.
Reorder the two subexpressions in the AND check, to perform the least
expensive check first.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/20191202155834.22582-1-geert+renesas@glider.be
Signed-off-by: Mark Brown <broonie@kernel.org>
---
sound/soc/sh/rcar/core.c | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 399dc6e9bde5..d20f03dfdee6 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -376,20 +376,15 @@ u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
*/
u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
{
- static const u32 dalign_values[8][2] = {
- {0x76543210, 0x67452301},
- {0x00000032, 0x00000023},
- {0x00007654, 0x00006745},
- {0x00000076, 0x00000067},
- {0xfedcba98, 0xefcdab89},
- {0x000000ba, 0x000000ab},
- {0x0000fedc, 0x0000efcd},
- {0x000000fe, 0x000000ef},
+ static const u32 dalign_values[8] = {
+ 0x76543210, 0x00000032, 0x00007654, 0x00000076,
+ 0xfedcba98, 0x000000ba, 0x0000fedc, 0x000000fe,
};
- int id = 0, inv;
+ int id = 0;
struct rsnd_mod *ssiu = rsnd_io_to_mod_ssiu(io);
struct rsnd_mod *target;
struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
+ u32 dalign;
/*
* *Hardware* L/R and *Software* L/R are inverted for 16bit data.
@@ -425,15 +420,15 @@ u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
if (mod == ssiu)
id = rsnd_mod_id_sub(mod);
- /* Non target mod or non 16bit needs normal DALIGN */
- if ((snd_pcm_format_width(runtime->format) != 16) ||
- (mod != target))
- inv = 0;
- /* Target mod needs inverted DALIGN when 16bit */
- else
- inv = 1;
+ dalign = dalign_values[id];
+
+ if (mod == target && snd_pcm_format_width(runtime->format) == 16) {
+ /* Target mod needs inverted DALIGN when 16bit */
+ dalign = (dalign & 0xf0f0f0f0) >> 4 |
+ (dalign & 0x0f0f0f0f) << 4;
+ }
- return dalign_values[id][inv];
+ return dalign;
}
u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-09 18:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02 15:58 [PATCH] ASoC: rsnd: Calculate DALIGN inversion at run-time Geert Uytterhoeven
2019-12-02 17:38 ` Eugeniu Rosca
2019-12-03 0:41 ` Kuninori Morimoto
2019-12-09 18:59 ` Applied "ASoC: rsnd: Calculate DALIGN inversion at run-time" to the asoc tree Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).