How to block Optimizer from certain files

New to XMOS and XCore? Get started here.
Post Reply
saul01
Member
Posts: 14
Joined: Thu Feb 16, 2017 12:57 am

How to block Optimizer from certain files

Post by saul01 »

Hi,
I am using USB (which requires -O3 optimization); however, this flag is just causing havoc in my code, some times my interfaces are optimized and and sometimes not. How can I block the Optimizer on certain files?

I am doing a simple task: communicating between two DSPs with a streaming channel, this works well until I add some unrelated code, after that, even if i just pass "0x00's" on the channel, I get just random data at the other end, and I repeat, this issue comes and goes.

Thanks.


robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

In general -Os is the recommended option.
-O2 & -O3 turn enable dual issue, but the compiler is poor at this at present.

If you have a function that needs to run fast, explicitly request dual issue for it via an attribute:

Code: Select all

[[dual_issue]] void f1() {
  return;
}
-O3 is only recommended per file.
If you are using the xcommon build system (yes if using xTimeComposer) this is done using:
XCC_FLAGS_<filename>
Overides the flags passed to xcc for the filename specified. This
option overides the flags for all build configurations.
search for 'Using XMOS Makefiles' for more information.

p.s. I doubt that there is a situation where -O2 or -O1 are at all useful.
saul01
Member
Posts: 14
Joined: Thu Feb 16, 2017 12:57 am

Post by saul01 »

Thanks! I will try it.
Just to give more detail on what I saw:
I run a test passing a 0x02 on a streaming channel across DSP tiles. Then on the receiving end I had:
if(sample == 0x02)
replace data with an increasing ramp to 255
else
replace data with an increasing ramp to 511.

I then sent the data using USB VCOM to PC, I was expecting to receive my ramp, but I got some random data! (I am using Movable Pointers to swap buffers).
So I added a local buffer (local to my task) where I was filling it with the ramp condition explained above (i.e. instead of using the movable pointer) and added a "memcopy" instruction to copy the local buffer to the movable... and all of the sudden my ramp data started to show correctly at the PC... so this tells me that the Optimizer is doing something really strange.

Anyway, I will do what you have suggested and post back my findings.
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

It is difficult to know what is happening in this situation.
The use of memcpy is however encouraged as the compiler knows all about it and can optimise memory usage around it.
For example it can decide the copy is not necessary, the copy is in shared memory, or the copy needs to happen over a channel.
In your situation, it may be that the compiler is allowing you to access remote memory using a local address - the memcpy is fixing this.
If you wish to report a simple case, I will confirm the bug and if it is fixed (14.3 will be released shortly).
saul01
Member
Posts: 14
Joined: Thu Feb 16, 2017 12:57 am

Post by saul01 »

Hello Robert,
So after lots of different ways of instantiating the tasks and their respective memory buffers, the application is working. I still would like to upload my code for review, I feel as if it is working by chance and not by a clear method that I have learnt. Is it ok for me to do that and how?

Our license expired Feb 19, but I am in the process of getting it renewed.

Thank you,

Saul
Post Reply