#Option Request

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
TimB
Posts: 262
Joined: Wed Oct 04, 2006 7:25 am
Location: London UK

#Option Request

Post by TimB » Thu Nov 23, 2006 7:49 pm

Hi

This is kind of a weird request, when converting some code over from Proton an issue was found. Now before you think I'm complaining, or saying one is better than the other I'm not!

Basically this is the situation, when the original in proton was written a feature of proton was used to great effect, this was the ability or the fact you declare alias by telling the compiler first that the alias is say a word, then its up to you to declare the next elements of the variable. i.e

Dim myarray[10] as byte
Dim Myword as myarray#0.word
Dim myarray#0h as myarray#1

Now its the last bit that is used to such great effect.

You could just as well say

Dim myarray[10] as byte
Dim Myword as myarray#1.word
Dim myarray#1h as myarray#0

So what does that mean?

Well by doing that you can work littleendian or Bigendian, why? Well in the ethernet conversion time is critical and the packets coming over are being parsed every 500us this is only been possible as no byte swapping was needed, it's handle automatically just by declaring a different variable name and method of aliasing.

So what about SF, I know you cannot do it and I do not want ask for anything that could break it.

So all I'm proposing is the ability to disable the auto alias function with a #define. Used at our own risk and only on say global variables. So it would be up to use to ensure the other variable is declared.

Any thoughts comment?

xor
Posts: 286
Joined: Sun Nov 05, 2006 1:15 pm
Location: NYC
Contact:

Post by xor » Fri Nov 24, 2006 4:27 am

I have to admit that compiler directives are new to me, although I owe a lot to the skilled users here and the great documentation which is opening a new world of compiler programming I never quite understood before.

I don't know if I'm understanding your proposal correctly, but I think that you are dimensioning a memory array as a sting of Bytes and also trying to define the same memory, or parts of that memory, as an array of Words. In other words, the 10-Byte array can also become a potential 5-Word array by grouping the bytes. Am I correct?

My approach, without using aliasing, is to use absolute addressing. Maybe something like this (not tested in the compiler):

Code: Select all

dim MyByteArray[10] as Byte Absolute $30
dim MyWordArray[5] as Word Absolute $30
These types of arrays are also easy to index. Again, I might be missing your point altogether. :?

TimB
Posts: 262
Joined: Wed Oct 04, 2006 7:25 am
Location: London UK

Post by TimB » Fri Nov 24, 2006 8:58 am

In SF you can alias any variable to any variable (within reason)

So you could just down load a big arrays worth of data. But rather than copy the elements of the array into another variable to manipulate them you work on the elements of the data directly in the array.

It save Var and code space.

SF though at the moment cannot alias an array to an array. All other var types are possible. Read the manual on Alias's

Back to my request. With ethernet data one layer is Bigendian and another will be Littlendian.

So the littlendian could be worked directly but the Bigendian you would have to copy it out and then swap the bytes. Before you can work on them and then again before you post them back.

What I was wanting is the ability to declare the elements of the array reversed so you did not have to remove, swap, process, swap, replace. You just do the processing directly.

An example

dim myarray[10] as byte
dim wordvar1 as myarray#2.word
dim myarray#2H as myarray#3
dim wordvar2 as myarray#3.word
dim myarray#3H as myarray#2

Now if I say wordvar1 = wordvar1 * 4 it would work on the array elements myarray[2] in littlendian format

But if I wrote wordvar2 = wordvar2 * 4 it would work on the array elements myarray[2] in Bigendian format.

The #define would be a compiler directive basically to enable me to turn of the FS auto complete feature. The saves my having to write the second line when I alias an array.

dim myarray#3H as myarray#2

BTW in SF you do not use the # its( )

dim Array(10) as byte
dim Lower as Array(0).AsLongWord
dim Upper as Array(4).AsLongWord

TimB
Posts: 262
Joined: Wed Oct 04, 2006 7:25 am
Location: London UK

Post by TimB » Fri Nov 24, 2006 9:31 am

As an aside, I think I have come up with a way to get round the problem at the array stuffing stage.

See not reason why it would not work.

And the overheads will be minimum

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Nov 24, 2006 3:50 pm

First a couple of points...

> dim MyByteArray[10] as Byte Absolute $30
> dim MyWordArray[5] as Word Absolute $30

You can do this in Swordfish, just remember to use round brackets. For example,

Code: Select all

dim MyByteArray(10) as byte absolute $30
dim MyWordArray(5) as word absolute $30
Also note that in Swordfish, using absolute is akin to using an alias. That is, no RAM is actually reserved. It overlays whatever is there. This feature is typically used to access some PIC RAM that is associated with a peripheral or register. Early compiler design tests showed that reserving blocks of RAM using absolute fragmented the procedure stack to unacceptable levels - so it is not used. In short, the above syntax is perfectly valid but used to map Swordfish RAM to specific PIC RAM.

> SF though at the moment cannot alias an array to an array.

You can alias an array in Swordfish. You just cannot alias an array to part of an array. For example,

Code: Select all

dim Array(10) as byte
dim Alias as Array
is perfectly valid. You can also use standard aliasing to an array. For example,

Code: Select all

dim Array(10) as byte                      // the array
dim AliasA as Array(0)                     // a byte, located at address 0
dim AliasB as Array(1).AsWord         // word, located at address 1
dim AliasC as Array(3).AsLongWord  // long word, located a address 3

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Nov 24, 2006 3:57 pm

> As an aside, I think I have come up with a way to get
> round the problem at the array stuffing stage.

I don't really see what you are trying to achieve as a big problem, but I can't be sure without seeing some snippets of code.

However, what you suggest seems to be the way forward. Rather than wasting time swapping bytes around, just read and put them into the correct array locations. Using AddressOf() or @ will give you the array address.

There are quite a few indirect addressing techniques (such as PLUSWn) which may provide an extremely efficient way for translating and storing the correct byte orientation.

TimB
Posts: 262
Joined: Wed Oct 04, 2006 7:25 am
Location: London UK

Post by TimB » Fri Nov 24, 2006 4:11 pm

I agree 100% with what you say for the sake of a few extra instructions it would be easier to swap the data coming into the correct format and then swap it back when its sent out.

The array thing was...

You cannot alias an 1 array of say 10 bytes then another of say 5 bytes to start at pos 3 onwards.

I have too say I could not think of any reason to do so. Personally I find Structures and types a fantastic addition to my normal programming style. So much more flexible.

I really need a meaty project to get my teeth into to make the most of this superb compiler.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Fri Nov 24, 2006 4:27 pm

> I agree 100% with what you say for the sake of a few
> extra instructions it would be easier to swap the data
> coming into the correct format and then swap it back
> when its sent out.

I think you are right in that it would only take a few extra instructions - quite a nice little 'code challenge' ;-)

> You cannot alias an 1 array of say 10 bytes then
> another of say 5 bytes to start at pos 3 onwards.

You are correct, you cannot do this

> Personally I find Structures and types a fantastic
> addition to my normal programming style. So much more flexible.

Just for reference, you can use absolute addressing with structures also...

Post Reply