Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #5320 > unrolled thread

Optimization problem

Started byhamze <hamze60@gmail.com>
First post2011-05-21 23:29 -0700
Last post2011-05-22 09:14 -0700
Articles 7 — 6 participants

Back to article view | Back to comp.lang.c++


Contents

  Optimization problem hamze <hamze60@gmail.com> - 2011-05-21 23:29 -0700
    Re: Optimization problem Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-22 01:25 -0700
      Re: Optimization problem hamze <hamze60@gmail.com> - 2011-05-22 01:47 -0700
        Re: Optimization problem Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-22 11:40 +0000
        Re: Optimization problem Pete Becker <pete@versatilecoding.com> - 2011-05-22 08:39 -0400
        Re: Optimization problem Nobody <nobody@nowhere.com> - 2011-05-22 15:01 +0100
        Re: Optimization problem Geoff <geoff@invalid.invalid> - 2011-05-22 09:14 -0700

#5320 — Optimization problem

Fromhamze <hamze60@gmail.com>
Date2011-05-21 23:29 -0700
SubjectOptimization problem
Message-ID<e627bb96-b05b-43ac-b6e8-e0ddaf62f9cc@l30g2000vbn.googlegroups.com>
I have a special device in my system, I must work with it in this
manner that : write 4 bytes and read 3 bytes,
this device has no reset, so if one of reads or writes miss, from that
time device will not work correctly because order of writes and reads
are missed.

this device works right when optimization is off, but when I turn it
on it stop working properly in my code.
some time i did not use one of its read value, so I think optimization
remove it and order of read and writes are missed.
how can I solve this problem ?
I also test this solution that I defined an asm valotile ( ) and put
all reads and write inside it but still turning optimization on
corrupt my program result.

[toc] | [next] | [standalone]


#5324

FromJoshua Maurice <joshuamaurice@gmail.com>
Date2011-05-22 01:25 -0700
Message-ID<db3320a1-d7d6-4337-af40-10ea1b9a76ee@q12g2000prb.googlegroups.com>
In reply to#5320
On May 21, 11:29 pm, hamze <hamz...@gmail.com> wrote:
> I have a special device in my system, I must work with it in this
> manner that : write 4 bytes and read 3 bytes,
> this device has no reset, so if one of reads or writes miss, from that
> time device will not work correctly because order of writes and reads
> are missed.
>
> this device works right when optimization is off, but when I turn it
> on it stop working properly in my code.
> some time i did not use one of its read value, so I think optimization
> remove it and order of read and writes are missed.
> how can I solve this problem ?
> I also test this solution that I defined an asm valotile ( ) and put
> all reads and write inside it but still turning optimization on
> corrupt my program result.

From what I've heard in this group, volatile alone is insufficient for
correct MMIO (memory mapped IO) on most systems. I would suggest
looking at the docs for your implementation to see what it says about
correct MMIO. You could also look at the output assembly to see if it
is indeed not doing as you want.

[toc] | [prev] | [next] | [standalone]


#5325

Fromhamze <hamze60@gmail.com>
Date2011-05-22 01:47 -0700
Message-ID<bdb12766-bf2e-4b3c-ab57-7f07e0e530f9@j25g2000vbr.googlegroups.com>
In reply to#5324
On May 22, 12:25 pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
> On May 21, 11:29 pm, hamze <hamz...@gmail.com> wrote:
>
> > I have a special device in my system, I must work with it in this
> > manner that : write 4 bytes and read 3 bytes,
> > this device has no reset, so if one of reads or writes miss, from that
> > time device will not work correctly because order of writes and reads
> > are missed.
>
> > this device works right when optimization is off, but when I turn it
> > on it stop working properly in my code.
> > some time i did not use one of its read value, so I think optimization
> > remove it and order of read and writes are missed.
> > how can I solve this problem ?
> > I also test this solution that I defined an asm valotile ( ) and put
> > all reads and write inside it but still turning optimization on
> > corrupt my program result.
>
> From what I've heard in this group, volatile alone is insufficient for
> correct MMIO (memory mapped IO) on most systems. I would suggest
> looking at the docs for your implementation to see what it says about
> correct MMIO. You could also look at the output assembly to see if it
> is indeed not doing as you want.

thanks alot, you gave me a valuable clue,
I know what is my hardware correct order of MMIO, but I dont know how
to make compiler know about it and force compile not to REORDER my
code.

[toc] | [prev] | [next] | [standalone]


#5330

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2011-05-22 11:40 +0000
Message-ID<slrniththe.gtj.grahn+nntp@frailea.sa.invalid>
In reply to#5325
On Sun, 2011-05-22, hamze wrote:
> On May 22, 12:25 pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
>> On May 21, 11:29 pm, hamze <hamz...@gmail.com> wrote:
>>
>> > I have a special device in my system, I must work with it in this
>> > manner that : write 4 bytes and read 3 bytes,
>> > this device has no reset, so if one of reads or writes miss, from that
>> > time device will not work correctly because order of writes and reads
>> > are missed.
>>
>> > this device works right when optimization is off, but when I turn it
>> > on it stop working properly in my code.
>> > some time i did not use one of its read value, so I think optimization
>> > remove it and order of read and writes are missed.
>> > how can I solve this problem ?
>> > I also test this solution that I defined an asm valotile ( ) and put
>> > all reads and write inside it but still turning optimization on
>> > corrupt my program result.
>>
>> From what I've heard in this group, volatile alone is insufficient for
>> correct MMIO (memory mapped IO) on most systems. I would suggest
>> looking at the docs for your implementation to see what it says about
>> correct MMIO. You could also look at the output assembly to see if it
>> is indeed not doing as you want.
>
> thanks alot, you gave me a valuable clue,
> I know what is my hardware correct order of MMIO, but I dont know how
> to make compiler know about it and force compile not to REORDER my
> code.

It's possible that the right thing to do is to write the critical
parts in assembly.  You can start with compiler-generated assembly and
modify that, to make it a bit easier.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .  .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#5334

FromPete Becker <pete@versatilecoding.com>
Date2011-05-22 08:39 -0400
Message-ID<2011052208390816587-pete@versatilecodingcom>
In reply to#5325
On 2011-05-22 04:47:20 -0400, hamze said:

> On May 22, 12:25 pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
>> On May 21, 11:29 pm, hamze <hamz...@gmail.com> wrote:
>> 
>>> I have a special device in my system, I must work with it in this
>>> manner that : write 4 bytes and read 3 bytes,
>>> this device has no reset, so if one of reads or writes miss, from that
>>> time device will not work correctly because order of writes and reads
>>> are missed.
>> 
>>> this device works right when optimization is off, but when I turn it
>>> on it stop working properly in my code.
>>> some time i did not use one of its read value, so I think optimization
>>> remove it and order of read and writes are missed.
>>> how can I solve this problem ?
>>> I also test this solution that I defined an asm valotile ( ) and put
>>> all reads and write inside it but still turning optimization on
>>> corrupt my program result.
>> 
>> From what I've heard in this group, volatile alone is insufficient for
>> correct MMIO (memory mapped IO) on most systems. I would suggest
>> looking at the docs for your implementation to see what it says about
>> correct MMIO. You could also look at the output assembly to see if it
>> is indeed not doing as you want.
> 
> thanks alot, you gave me a valuable clue,
> I know what is my hardware correct order of MMIO, but I dont know how
> to make compiler know about it and force compile not to REORDER my
> code.

Since there's no code here, just a bunch of hand-waving, it's 
impossible to say definitively what's going on. But the compiler is not 
allowed to reorder or combine accesses to volatile objects.

-- 
  Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The 
Standard C++ Library Extensions: a Tutorial and Reference 
(www.petebecker.com/tr1book)

[toc] | [prev] | [next] | [standalone]


#5338

FromNobody <nobody@nowhere.com>
Date2011-05-22 15:01 +0100
Message-ID<pan.2011.05.22.14.00.59.484000@nowhere.com>
In reply to#5325
On Sun, 22 May 2011 01:47:20 -0700, hamze wrote:

> I know what is my hardware correct order of MMIO, but I dont know how
> to make compiler know about it and force compile not to REORDER my
> code.

The compiler will not re-order reads/writes of volatile variables with
respect to each other. However, the CPU might perform re-ordering; to
prevent this, you need to use a memory barrier (aka "fence").

	http://en.wikipedia.org/wiki/Memory_barrier
	http://en.wikipedia.org/wiki/Memory_ordering

For gcc, see e.g.:

http://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Atomic-Builtins.html

Also, you might try comp.arch.embedded.

[toc] | [prev] | [next] | [standalone]


#5341

FromGeoff <geoff@invalid.invalid>
Date2011-05-22 09:14 -0700
Message-ID<97dit6dec8engcjdroaqnoldc4jnpvcjc5@4ax.com>
In reply to#5325
On Sun, 22 May 2011 01:47:20 -0700 (PDT), hamze <hamze60@gmail.com>
wrote:

>On May 22, 12:25 pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
>> On May 21, 11:29 pm, hamze <hamz...@gmail.com> wrote:
>>
>> > I have a special device in my system, I must work with it in this
>> > manner that : write 4 bytes and read 3 bytes,
>> > this device has no reset, so if one of reads or writes miss, from that
>> > time device will not work correctly because order of writes and reads
>> > are missed.
>>
>> > this device works right when optimization is off, but when I turn it
>> > on it stop working properly in my code.
>> > some time i did not use one of its read value, so I think optimization
>> > remove it and order of read and writes are missed.
>> > how can I solve this problem ?
>> > I also test this solution that I defined an asm valotile ( ) and put
>> > all reads and write inside it but still turning optimization on
>> > corrupt my program result.
>>
>> From what I've heard in this group, volatile alone is insufficient for
>> correct MMIO (memory mapped IO) on most systems. I would suggest
>> looking at the docs for your implementation to see what it says about
>> correct MMIO. You could also look at the output assembly to see if it
>> is indeed not doing as you want.
>
>thanks alot, you gave me a valuable clue,
>I know what is my hardware correct order of MMIO, but I dont know how
>to make compiler know about it and force compile not to REORDER my
>code.

Get to know your compiler and target CPU. Microsoft provides the
#pragma optimize directive for turning optimizations off/on for
individual functions.

Write your low-level MM I/O functions in assembler, call them from C.
 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web