All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kenneth Johansson <kenneth@southpole.se>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] Sample generation on big endian platforms was broken.
Date: Fri, 03 Jul 2009 17:58:50 +0200	[thread overview]
Message-ID: <1246636730.7922.67.camel@localhost.localdomain> (raw)
In-Reply-To: <s5hws6phjk8.wl%tiwai@suse.de>

On Fri, 2009-07-03 at 17:28 +0200, Takashi Iwai wrote:
> At Fri, 03 Jul 2009 17:11:37 +0200,
> Kenneth Johansson wrote:
> > 
> > On Fri, 2009-07-03 at 17:00 +0200, Takashi Iwai wrote:
> > > At Fri, 03 Jul 2009 16:51:35 +0200,
> > > Kenneth Johansson wrote:
> > > > 
> > > > On Fri, 2009-07-03 at 16:39 +0200, Takashi Iwai wrote:
> > > > > At Fri, 03 Jul 2009 16:19:31 +0200,
> > > > > Kenneth Johansson wrote:
> > > > > > 
> > > > > > Has not worked since commit 3d1fa924906996463ac33cba5b5143f762d913cf
> > > > > > 
> > > > > > Signed-off-by: Kenneth Johansson <kenneth@southpole.se>
> > > > > 
> > > > > Hrm, sorry, but your version is also broken as doing type-punning.
> > > > > The code has to be rewritten completely...
> > > > > 
> > > > > 
> > > > > Takashi
> > > > 
> > > > hmm I think you have to explain this. now it works on both little/big
> > > > endian without any explicit byte moves.
> > > > 
> > > > It did not understand what problem you see.
> > > 
> > > You can't cast from a char pointer to another type (e.g. short) and
> > > read the value.  This is called "type-punning" and doesn't work
> > > properly with the recent GCC (depending on the optimization and
> > > code parsing) since it handles strict-aliasing.
> > > 
> > > See GCC info for details.
> > > 
> > > 
> > > Takashi
> > 
> > But there is no aliasing problem in that code. The memory is only
> > accessed(written in this case) using one type.
> 
> One type?
> 
> +			switch(bps){
> +			case 1:
> +				*(samples[chn]) = res;
> +				break;
> +			case 2:
> +				*(short*)(samples[chn]) = res;
> +				break;
> +			case 4:
> +				*(int*)(samples[chn]) = res;
> +			}

But only one of them will ever be used. whenever this function is
entered the pointer is only using one type ever. the memory is never
accessed with any other type and it's only using this one pointer. 

What exactly do you think the compiler can do ?? it's not like it can
cache the samples[chn] value that is the char pointer and make a
constant pointer out of it. There is no mixed type accesses. 

Aliasing happens when two pointers of different type point to the same
memory. then you can have funny things happening if you access the
memory from the two pointers. 

There is no pointer aliasing here there is only one pointer. We just
change the type of this one pointer in the one place it's used.

Is it aliasing with itself ? would the write magically happen in some
other size or not at all what ??  

could you point me to some documentation for this I'm not getting it.

  parent reply	other threads:[~2009-07-03 15:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-03 14:19 [PATCH] Sample generation on big endian platforms was broken Kenneth Johansson
2009-07-03 14:39 ` Takashi Iwai
2009-07-03 14:51   ` Kenneth Johansson
2009-07-03 15:00     ` Takashi Iwai
2009-07-03 15:11       ` Kenneth Johansson
2009-07-03 15:28         ` Takashi Iwai
2009-07-03 15:41           ` Takashi Iwai
2009-07-03 17:04             ` Kenneth Johansson
2009-07-03 19:36               ` Takashi Iwai
2009-07-03 15:58           ` Kenneth Johansson [this message]
2009-07-03 16:59             ` Takashi Iwai

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=1246636730.7922.67.camel@localhost.localdomain \
    --to=kenneth@southpole.se \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.