Parmenides | 1 Jul 2011 17:28
Picon

Re: Can a float volatile asm be used as optimization barrier?

>
> As is documented in the gcc manual, "asm
> volatile" means that the instruction has side effects which are not
> described in the outputs, and thus may not be deleted.

I think it necessary to get my feet wet for side effects. I try to
modify an example in gcc manual to make it adapt to IA32.

#define add(new)                                \
     ({ int __old;                              \
          asm ("addl %1, %0"                    \
               : "=g" (__old) : "g" (new));     \
          __old;                                \
     })

void tst(void)
{
     int x = 15;
     add(x);
}

Then, I invoked gcc to compile it :
gcc -S -O tst.c

and, get the following asm code :
tst:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
(Continue reading)

Segher Boessenkool | 1 Jul 2011 18:35

Re: Can a float volatile asm be used as optimization barrier?

> #define add(new)                                \
>      ({ int __old;                              \
>           asm ("addl %1, %0"                    \
>                : "=g" (__old) : "g" (new));     \
>           __old;                                \
>      })
>
> void tst(void)
> {
>      int x = 15;
>      add(x);
> }

> But according to gcc manual, "if an asm has output operands, GCC
> assumes for optimization purposes the instruction has no side effects
> except to change the output operands."
>
> In the above example, it is obvious that the asm has an output
> operand. But, in terms of the inline instruction, namely the addl, the
> output operand is **changed** indeed. Why does the gcc consider the
> asm having no side effects?

It considers the asm as having no side effects _except to change the
output operands_.  You didn't use the output, so GCC is free to remove
the asm altogether: the resulting assembler code will still do the same
thing (namely, nothing).

Segher

(Continue reading)

Ian Lance Taylor | 1 Jul 2011 19:24
Picon
Favicon
Gravatar

Re: Can a float volatile asm be used as optimization barrier?

Parmenides <mobile.parmenides <at> gmail.com> writes:

> I think it necessary to get my feet wet for side effects. I try to
> modify an example in gcc manual to make it adapt to IA32.
>
> #define add(new)                                \
>      ({ int __old;                              \
>           asm ("addl %1, %0"                    \
>                : "=g" (__old) : "g" (new));     \
>           __old;                                \
>      })
>
> void tst(void)
> {
>      int x = 15;
>      add(x);
> }
>
> Then, I invoked gcc to compile it :
> gcc -S -O tst.c
>
> and, get the following asm code :
> tst:
>         pushl   %ebp
>         movl    %esp, %ebp
>         popl    %ebp
>         ret
>
> It seems that the asm instruction has been considered having no side
> effects and deleted from tst(), because the __old is declared as
(Continue reading)

kevin diggs | 1 Jul 2011 20:06
Picon

Re: Can a float volatile asm be used as optimization barrier?

Hi,

Something like:

#define add(new)			\
	({int __old;			\
		asm("addl %1,%0\n\t"	\
			:"=g"(__old)	\
			:"g"(new));	\
					\
		__old;			\
	})

int tst(int in)
{
int y;

	y=add(in);

	return y;
}

kevin

Michał Walenciak | 1 Jul 2011 22:55
Picon

forcing gcc to use a nonstandard list of include directories

Hi all

I'm trying to compile gcc for an avr architecture.
I've used standard directories in ./configure (--prefix=/usr etc).
The only except is --exec-prefix which I set to /usr/lib so gcc looks for avr 
related files in /usr/lib/avr/. That all is fine except includes. gcc keeps 
using default set of includes (with nonexisting /usr/avr/include). I wish it 
was looking for .h files in /usr/lib/avr/includes (and only there! as 
/usr/include & co dirs are inappropriate for avr architecture). 

How can I simply achieve that?

best regards

--

-- 
Michał Walenciak
gmail.com kicer86
http://kicer.sileman.net.pl
gg: 3729519

Jonathan Wakely | 1 Jul 2011 23:00
Picon

Re: forcing gcc to use a nonstandard list of include directories

On 1 July 2011 21:55, Michał Walenciak wrote:
> Hi all
>
> I'm trying to compile gcc for an avr architecture.
> I've used standard directories in ./configure (--prefix=/usr etc).

It will be a lot easier for people to help if you say what you
*actually* did, not "etc."

Running ./configure isn't supported, you should build outside the
source directory.

Parmenides | 2 Jul 2011 01:01
Picon

Re: Can a float volatile asm be used as optimization barrier?

> This is exactly what the manual says.  The asm has no side-effects
> except to change __old.  And __old is not used, which means that any
> statements which assign a value to __old are unnecessary and may be
> removed.  Since the only effect of the asm is to change __old, it is
> removed.

I really have gotten a misunstanding about the manual. ;-)
Thanks a lot.

Michał Walenciak | 2 Jul 2011 07:55
Picon

Re: forcing gcc to use a nonstandard list of include directories

Dnia piątek 01 lipca 2011 o 23:00:56 Jonathan Wakely napisał(a):
> On 1 July 2011 21:55, Michał Walenciak wrote:
> > Hi all
> > 
> > I'm trying to compile gcc for an avr architecture.
> > I've used standard directories in ./configure (--prefix=/usr etc).
> 
> It will be a lot easier for people to help if you say what you
> *actually* did, not "etc."
> 
> Running ./configure isn't supported, you should build outside the
> source directory.

I use distro's tools for builing, and whole ./configure looks like:
+ export CONFIGURE_TOP=../gcc-4.5.3
+ CONFIGURE_TOP=../gcc-4.5.3
+ CFLAGS='-O2 -g -pipe -Wformat -Werror=format-security -Wp,-
D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4'
+ export CFLAGS
+ CXXFLAGS='-O2 -g -pipe -Wformat -Werror=format-security -Wp,-
D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4'
+ export CXXFLAGS
+ FFLAGS='-O2 -g -pipe -Wformat -Werror=format-security -Wp,-
D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4'
+ export FFLAGS
+ LDFLAGS=' -Wl,--as-needed -Wl,--no-undefined -Wl,-z,relro -Wl,-O1 -Wl,--
build-id -Wl,--enable-new-dtags'
+ export LDFLAGS
+ CONFIGURE_TOP=../gcc-4.5.3
+ /usr/lib/rpm/mageia/force-as-needed-for-shared-lib-in-libtool
(Continue reading)

eric | 2 Jul 2011 10:53
Picon

makefile in textbook example not work(at stage of make install), plz help

Dear advanced c++ programers:

  I tried to copy and test a piece simple makefile code with
simple .cpp, .hpp code(s) which purpose is teach reader
how to use gnu make (especially on unix/linux) build (complex
application).  That is the book (C++ Cookbook) chapter 1
example 1-2
              1-3
              1-20
              1-22
              1-23
              1-24
-------------------------------------------------but it failed at
stage of make install (make TARGET=install)--------------
-------the following is after
make-------------------------------------------------------------------------------------------------------

eric <at> eric-laptop:~/cppcookbook/ch1$ ls
binaries  georgeringo  hellobeatles  johnpaul  Makefile
eric <at> eric-laptop:~/cppcookbook/ch1$ make TARGET=install
make --directory=johnpaul install
make[1]: Entering directory `/home/eric/cppcookbook/ch1/johnpaul'
mkdir -p ../binaries
cp -p libjohnpaul.a ../binaries
make[1]: Leaving directory `/home/eric/cppcookbook/ch1/johnpaul'
make --directory=georgeringo install
make[1]: Entering directory `/home/eric/cppcookbook/ch1/georgeringo'
mkdir -p ../binaries
cp -p libgeorgeringo.so ../binaries
make[1]: Leaving directory `/home/eric/cppcookbook/ch1/georgeringo'
(Continue reading)

Jonathan Wakely | 2 Jul 2011 12:59
Picon

Re: forcing gcc to use a nonstandard list of include directories

On 2 July 2011 06:55, Michał Walenciak wrote:
> datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --

Hmm, I wonder why it's using /usr/include for include files

I wouldn't have thought it's a good idea to install a cross-compiler
as /usr/bin/gcc anyway


Gmane