Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Optimization problem

Reply
Thread Tools

Optimization problem

 
 
hamze
Guest
Posts: n/a
 
      05-22-2011
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.
 
Reply With Quote
 
 
 
 
Joshua Maurice
Guest
Posts: n/a
 
      05-22-2011
On May 21, 11:29*pm, hamze <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
hamze
Guest
Posts: n/a
 
      05-22-2011
On May 22, 12:25*pm, Joshua Maurice <(E-Mail Removed)> wrote:
> On May 21, 11:29*pm, hamze <(E-Mail Removed)> 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.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      05-22-2011
On Sun, 2011-05-22, hamze wrote:
> On May 22, 12:25*pm, Joshua Maurice <(E-Mail Removed)> wrote:
>> On May 21, 11:29*pm, hamze <(E-Mail Removed)> 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 .
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      05-22-2011
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....-Builtins.html

Also, you might try comp.arch.embedded.

 
Reply With Quote
 
Geoff
Guest
Posts: n/a
 
      05-22-2011
On Sun, 22 May 2011 01:47:20 -0700 (PDT), hamze <(E-Mail Removed)>
wrote:

>On May 22, 12:25*pm, Joshua Maurice <(E-Mail Removed)> wrote:
>> On May 21, 11:29*pm, hamze <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zero Optimization and Sign Optimization??? Ravikiran C Programming 22 11-24-2008 03:19 AM
problem in optimization of vhdl code ashu VHDL 5 05-16-2006 03:48 PM
HTML tags optimization [ interesting problem] DENG Python 6 09-02-2005 01:16 PM
Optimization problem, for a sports tournament JE C++ 2 08-05-2004 08:22 AM
Optimization problem, for a sports tournament JE Perl 0 08-04-2004 06:52 PM



Advertisments