DSPRelated.com
Forums

SIMD mode in FOR loop

Started by abhi...@wipro.com August 3, 2006
hello all,

I am currently working on ADSP 21365 SHARC processor. I want to know "How processor will behave in case of Enabling and disabling SIMD mode in for loop"? Will processor work properly or not?
please refer to below sample code.
------------------
bit set mode1 PEYEN;
nop;
LCNTR = 256, do loop_end until LCE;
// some code here
......
bit clr mode1 PEYEN;
nop;
// some code here which is not in SIMD mode
......
bit set mode1 PEYEN;
nop;
// some code here
......
loop_end: nop;
bit set mode1 PEYEN;
nop;
------------------
will this kind of code work successfully or not?

Thanks
Abhi
On Wednesday 02 August 2006 20:07, a...@wipro.com wrote:
> hello all,
>
> I am currently working on ADSP 21365 SHARC processor. I want to know "How
> processor will behave in case of Enabling and disabling SIMD mode in for
> loop"? Will processor work properly or not? please refer to below sample
> code.
> ------------------
> bit set mode1 PEYEN;
> nop;
> LCNTR = 256, do loop_end until LCE;
> // some code here
> ......
> bit clr mode1 PEYEN;
> nop;
> // some code here which is not in SIMD mode
> ......
> bit set mode1 PEYEN;
> nop;
> // some code here
> ......
> loop_end: nop;
> bit set mode1 PEYEN;
> nop;
> ------------------
> will this kind of code work successfully or not?
>
> Thanks
> Abhi

>From my experience, I'd expect it to work.
However, I'd try to avoid switching PEYEN within the loop.
(costs time, reduces readability, increases chance for coding-errors)
Maybe you can just provide "dummy code" for the Y register set,
so that you can keep SIMD on, and just ignore
the results of the second set.
In the end this might be faster, more readable (just add a line of comment)
and remove the ugly switches.
Most critical is your idea, if conditional branches are used in either
section. You always must pay attention to the PEYEN state before and after a
jump/call.
Keep also in mind, that ISRs (interrupt service routines) usually switch off
SIMD - make sure that you don't interfere with ISR prologues/epilogues, which
is not always evident. This is most important if you want to work in ISRs.
Bernhard

----
Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie
die unbefugte Weitergabe dieser Mail ist nicht gestattet.
Ueber das Internet versandte E-Mails koennen leicht unter fremden Namen
erstellt oder manipuliert werden. Aus diesem Grunde bitten wir um
Verstaendnis, dass wir zu Ihrem und unserem Schutz die rechtliche
Verbindlichkeit der vorstehenden Erklaerungen und Aeusserungen
ausschliessen.

This E-mail may contain confidential and/or privileged information. If
you are not the intended recipient or have received this E-mail in
error, please notify the sender immediately and destroy this E-mail. Any
unauthorized copying, disclosure or distribution of the material in this
E-mail is strictly forbidden.
E-mails via Internet can easily be prepared or manipulated by third
persons. For this reason we trust you will understand that, for your own
and our protection, we rule out the legal validity of the foregoing
statements and comments.

On Thursday 03 August 2006 14:53, a...@wipro.com wrote:
> Hi Bernhard,
>
> Thanks for your comments.
> I had tried this switching and it is working well, but till now I had not
> found anything for validity of this kind of switching in Reference manuals.
> Can you put some more light on this?
>
> Regards,
> Abhi

Since ISRs switch SIMD off/on very often, if they happen to interrupt a SIMD
region, switching must be robust enough to do so, or ISRs wouldn't work
within SIMD regions. But they do.
Besides: be aware of nesting, if you work with SIMD inside ISRs.
The problem of interrupts is, that you usually check if they don't modify used
registers. But there's a good chance that you forget to restore the registers
in the PEy, because their use isn't visible in the code.

Another issue, which is easily overseen:
usually you read from memory with a command like
r2=dm(i2,m6);
the implicit (background) execution is s2=dm(i2+1,m6)
Usually, the hidden part works on the +1,
however, if i2 is impair, this is not always the case (see manual).
To avoid such conflicts, just make sure that i2 is always loaded with
perfectly aligned addresses.

Check ADSP-2136xSHARC Processor Programming Reference p. 2.44-2.52,
ch. 8+9, and at lots of additional locations.
Read this very!! thoroughly, because lots of complex (complicated?)
information is hidden here!
Your most wanted piece of information is on p. 2.45: one cycle delay ...

Your code correctly reflected this with the NOPs.
However, you can easily avoid the NOP, as long as the next statement following
the set/clr PEYEN statement is one, which has the same effect in SIMD and
SISD mode. For example, if you switch PEYEN on and the load LCNTR, this is
not a problem. You can do it immediately after the switch, and thus save
time.
However, I do always insert a comment after the set/clr PEYEN command
which tells that a SIMD/SISD robust statement must follow.
Just to remember me or others later.

Bernhard

----
Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie
die unbefugte Weitergabe dieser Mail ist nicht gestattet.
Ueber das Internet versandte E-Mails koennen leicht unter fremden Namen
erstellt oder manipuliert werden. Aus diesem Grunde bitten wir um
Verstaendnis, dass wir zu Ihrem und unserem Schutz die rechtliche
Verbindlichkeit der vorstehenden Erklaerungen und Aeusserungen
ausschliessen.

This E-mail may contain confidential and/or privileged information. If
you are not the intended recipient or have received this E-mail in
error, please notify the sender immediately and destroy this E-mail. Any
unauthorized copying, disclosure or distribution of the material in this
E-mail is strictly forbidden.
E-mails via Internet can easily be prepared or manipulated by third
persons. For this reason we trust you will understand that, for your own
and our protection, we rule out the legal validity of the foregoing
statements and comments.
Hi,

Properly working or not, depends on what is the SIMD
and not-SIMD code supposed to do.

The SIMD enabling/disabling is as simple as that.
changing a bit in the control register.

JaaC

--- a...@wipro.com wrote:

> hello all,
>
> I am currently working on ADSP 21365 SHARC
> processor. I want to know "How processor will behave
> in case of Enabling and disabling SIMD mode in for
> loop"? Will processor work properly or not?
> please refer to below sample code.
>
------------------
> bit set mode1 PEYEN;
> nop;
> LCNTR = 256, do loop_end until LCE;
> // some code here
> ......
> bit clr mode1 PEYEN;
> nop;
> // some code here which is not in SIMD mode
> ......
> bit set mode1 PEYEN;
> nop;
> // some code here
> ......
> loop_end: nop;
> bit set mode1 PEYEN;
> nop;
>
------------------
> will this kind of code work successfully or not?
>
> Thanks
> Abhi
>
> a...
>
>

Jaime Andr Aranguren Cardona
j...@ieee.org
j...@computer.org
__________________________________________________
On Monday 14 August 2006 17:50, Jaime Andres Aranguren Cardona wrote:
> Hi,
>
> Properly working or not, depends on what is the SIMD
> and not-SIMD code supposed to do.
>
> The SIMD enabling/disabling is as simple as that.
> changing a bit in the control register.
>
> JaaC

Hi JaaC,
you're correct.
And how it works, is very well described in the manuals.

However, for somebody who has not dealt with SIMD before
(as I can remember from my experiences a couple of years ago),
it may seem very obscure, what happens in the background, with no appropriate
code being actually written somewhere.

Hint to all SIMD beginners:
start with very handy (small) code and allow yourself to learn by doing.
A strategy might be to start in SISD mode, and explicitely coding everything
which is expected to be done in background while SIMD is on.
Seeing the difference of both code fragments will enlighten the understanding.

Bernhard

----
Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie
die unbefugte Weitergabe dieser Mail ist nicht gestattet.
Ueber das Internet versandte E-Mails koennen leicht unter fremden Namen
erstellt oder manipuliert werden. Aus diesem Grunde bitten wir um
Verstaendnis, dass wir zu Ihrem und unserem Schutz die rechtliche
Verbindlichkeit der vorstehenden Erklaerungen und Aeusserungen
ausschliessen.

This E-mail may contain confidential and/or privileged information. If
you are not the intended recipient or have received this E-mail in
error, please notify the sender immediately and destroy this E-mail. Any
unauthorized copying, disclosure or distribution of the material in this
E-mail is strictly forbidden.
E-mails via Internet can easily be prepared or manipulated by third
persons. For this reason we trust you will understand that, for your own
and our protection, we rule out the legal validity of the foregoing
statements and comments.
--- Bernhard Holzmayer
wrote:

> However, for somebody who has not dealt with SIMD
> before
> (as I can remember from my experiences a couple of
> years ago),
> it may seem very obscure, what happens in the
> background, with no appropriate
> code being actually written somewhere.
>
> Hint to all SIMD beginners:
> start with very handy (small) code and allow
> yourself to learn by doing.
> A strategy might be to start in SISD mode, and
> explicitely coding everything
> which is expected to be done in background while
> SIMD is on.
> Seeing the difference of both code fragments will
> enlighten the understanding.
>
> Bernhard

Hello,

What a great comment, Bernhard! Very didactic and
enlighting.

Those are the techniques that one trained into taking
learning curves knows, and thanks for sharing
knowledge and advices with the community.

Regards,

JaaC
Jaime Andr Aranguren Cardona
j...@ieee.org
j...@computer.org
__________________________________________________