Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
rr

Homepage E-mail

Berlin, Germany,
17.09.2008, 18:01
 

GCC's "-fno-strict-aliasing"? (Developers)

Can anyone explain GCC's -fno-strict-aliasing to me? It's used by QEMU. I've read the docs, but still don't have clue, when what it's for and it's save to use. Explanations in German preferred. ;-)

---
Forum admin

marcov

18.09.2008, 10:30

@ rr
 

GCC's "-fno-strict-aliasing"?

> Can anyone explain GCC's -fno-strict-aliasing to me? It's used
> by QEMU. I've read the docs, but still don't have clue, when what it's for
> and it's save to use. Explanations in German preferred. ;-)

As far as I know does the C standard has a few rules about aliassing. An alias is e.g. if you have two pointers of different types, then C assumes that they can't point to the same memory. (IOW one can't be an alias of the other)

A compiler can use that to optimize and reorder statements and assignments.
-fno-strict-aliasing turns of that optimization, IOW their code is dirty and not ANSI C compatible.

So it turns off a valid optimization. It is afaik a typical optimization that is turned globally off if "strange" things happen.

rr

Homepage E-mail

Berlin, Germany,
18.09.2008, 11:37

@ marcov
 

GCC's "-fno-strict-aliasing"?

> As far as I know does the C standard has a few rules about aliassing. An
> alias is e.g. if you have two pointers of different types, then C assumes
> that they can't point to the same memory. (IOW one can't be an alias of
> the other)

That's also in the docs. ;-)

> A compiler can use that to optimize and reorder statements and
> assignments.
> -fno-strict-aliasing turns of that optimization, IOW their code is dirty
> and not ANSI C compatible.

But why is, e.g., Zlib faster then, if -fno-strict-aliasing turns off that optimization?

> So it turns off a valid optimization. It is afaik a typical optimization
> that is turned globally off if "strange" things happen.

I see. ;-)

---
Forum admin

marcov

18.09.2008, 13:20

@ rr
 

GCC's "-fno-strict-aliasing"?

> > A compiler can use that to optimize and reorder statements and
> > assignments.
> > -fno-strict-aliasing turns of that optimization, IOW their code is
> dirty
> > and not ANSI C compatible.
>
> But why is, e.g., Zlib faster then, if -fno-strict-aliasing turns off that
> optimization?

Probably becuase the loop is hand tuned at a certain setting to perform maximally. Compiler reordering might work against it.

If you really want to know, do what all compiler hacks do. Find a piece of source where it matters, objdump both .o and diff.

(probably needs a small script to filter out changing assembler label numbers)

RayeR

Homepage

CZ,
18.09.2008, 14:10

@ marcov
 

GCC's "-fno-strict-aliasing"?

> As far as I know does the C standard has a few rules about aliassing. An
> alias is e.g. if you have two pointers of different types, then C assumes
> that they can't point to the same memory.

Did you mean something like this?

unsigned long *p1;
unsigned char p2[4]={1,2,3,4};

p1=(unsigned long *)p2;

Is p1 alias of p2? What's wrong on this code? Will it fails to compile if -fno-strict-aliasing enabled? U use such things of retyping very often, eg. when you have a char buffer and you want to access it as a structure.

---
DOS gives me freedom to unlimited HW access.

rr

Homepage E-mail

Berlin, Germany,
25.09.2008, 16:38

@ rr
 

GCC's "-fno-strict-aliasing"?

> Can anyone explain GCC's -fno-strict-aliasing to me? It's used
> by QEMU. I've read the docs, but still don't have clue, when what it's for
> and it's save to use. Explanations in German preferred. ;-)

Today I found this article by Mike Acton of CellPerformance: Understanding Strict Aliasing

---
Forum admin

RayeR

Homepage

CZ,
29.09.2008, 17:09

@ rr
 

GCC's "-fno-strict-aliasing"?

> Today I found this article by Mike Acton of CellPerformance:
> Understanding
> Strict Aliasing

Thanks, interesting article and also more from this author.

---
DOS gives me freedom to unlimited HW access.

Back to index page
Thread view  Board view
22752 Postings in 2119 Threads, 402 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum