At the moment there's probably not very much you can do to reduce COG usage. Breaking large functions/subroutines up into smaller ones might help, and of course if you have any code explicitly placed in COG you should move it to LUT or HUB. I'm working on making the COG space used selectable via the --fcache option, which will make it possible to tweak the space for your application.
@JRoark : I've posted an updated beta on Patreon that has a smaller default for the FCACHE area (so more COG ram available) and also the ability to specify a different the FCACHE area size on the command line.
@ersmith said:
@JRoark : I've posted an updated beta on Patreon that has a smaller default for the FCACHE area (so more COG ram available) and also the ability to specify a different the FCACHE area size on the command line.
Awesome! I’ll see how she flies in a bit. Thanks, Eric.
@ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:
The problem I had with any/all optimization levels has been fixed. No more errors.
The long-standing problem I had where -O2 (full optimization) broke the compiler when used on large .BAS files is cured! SWEET!!
I also discovered some "hidden" gems that are not documented in the FlexBASIC doc, but appear to work are look to be deriviatives of functions found in the general compiler docs. They are:
@ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:@ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:
@Rayman said:
@ersmith Should C defines act line Spin2 constants in included .spin2 files?
I tried this: #define VGA_BASEPIN 48
But, it says unknown symbol, so I'm guessing this doesn't work... Should/Can it?
No, for several reasons:
(1) Objects created in C with "struct __using" are like objects created with OBJ in Spin2. The constants in the top level file don't go down into the sub-objects; similarly, constants in the C file don't go into the objects either.
(2) #define is actually even weaker than constants in CON. A #define creates a macro where every occurance of the symbol is replaced with the text after it. So after #define VGA_BASEPIN 48the result is literally as if you did a search-and-replace inside the .c file and replaced every instance of VGA_BASEPIN with 48. It's a text substitution only, and only works within that specific file.
@ersmith said:
@deets : the version in github now has support for DEBUG_BAUD.
Sorry for the delay, but I'm a bit too knackered under the week to get to my playtime stuff. But I just verified - works as advertised, thanks for the quick implementation! It seems the default is 230400, pnut allegedly uses 2_000_000. Just FYI if congruence is relevant to you here. Or the spin doc is wrong
@ersmith On the subject of suggestions, I have two for your consideration:
The predefined symbol __FLEXBASIC__ is defined as the compiler version (currently "5"). Could we change this (or create a new symbol) that includes the major, minor, revision, (ie, "5.4.0")?
Would it be possible to have another predefined symbol that contains the host date/time when the file was compiled? Something like Sun 25Aug2021 12:34:56 or whatever format the standard C language uses?
@JRoark : Those sound like good ideas, thanks. To get all 4 components of the version into the symbol it'll have to be a string rather than an integer, so I think I'll make a new symbol __FLEXBASIC_VERSION__ for that.
EDIT: Looks like there's already a __VERSION__symbol defined. I guess I forgot to document that, I'll add it to the manual.
Should things like _rnd() also be in the manual? Or, should there be Propeller2.h manual that is separate?
I was also thinking about getting the time in there somehow... Maybe better with loadp2? Was thinking about an easy way to initialize a real time clock...
Yes, _rnd() should be documented. There's probably quite a lot of stuff missing from the documentation, sorry. Although I'm always happy to accept pull requests .
As for time, not sure what the best approach to that is. Probably a new function call that communicates with the host via loadp2 to get the time, something like the existing file server. Is that the kind of thing you were thinking of?
@Rayman said:
Maybe Plan9 provides time already? If not directly, maybe I could create a new dummy file and then get the time from that file stats?
You're right, if you create a dummy file on the host and then do a stat() on it you could get the time that way. That's a nice idea, and saves having to add anything to loadp2.
@TonyB_ said:
Could FlexSpin please support/tolerate a colon at the end of a label?
One could then search for routine: without matching all the call #routine
PNut doesn't support this though, does it? I'm reluctant to introduce more incompatibilities with PNut, especially in the assembly language.
One work-around would be to use a capital letter in the actual label definition (like Routine) and lower case in the uses (call #routine). Spin is case insensitive, so this should work in all assemblers.
@TonyB_ said:
Could FlexSpin please support/tolerate a colon at the end of a label?
One could then search for routine: without matching all the call #routine
PNut doesn't support this though, does it? I'm reluctant to introduce more incompatibilities with PNut, especially in the assembly language.
One work-around would be to use a capital letter in the actual label definition (like Routine) and lower case in the uses (call #routine). Spin is case insensitive, so this should work in all assemblers.
Is colon a valid character in a PASM2 label, in either PNut or FlexSpin? I can't run PNut and I need to use FlexSpin anyway as #include is vital.
Changing the subject, is it possible to concatenate binary constants? E.g. if a = %1011 and b = %0010 can I combine a and b to get %10110010? This would be very handy for skip pattern bits.
@TonyB_ said:
Changing the subject, is it possible to concatenate binary constants? E.g. if a = %1011 and b = %0010 can I combine a and b to get %10110010? This would be very handy for skip pattern bits.
a and b are stored as 32 bit values internally, so leading 0's are lost. So no, you can't concatenate them, because once they're parsed there's no way to know how wide they're "supposed" to be.
Ok, maybe the above idea is just not a good idea...
Instead of making an I2C code structure, I'll do what other C I2C codes I've seen do and create a structure that just has port specific things like timing and pin #s in it.
@Rayman said:
I guess the above usage is C++ an so not going to work here...
Yes, in C enums are always global, this is part of the language spec so I can't change it. In C++ they can be part of classes though, and flexspin will use that semantics if the file ends in ".cpp" or ".c++"; then they can be accessed by something like "x.THE_CONSTANT".
Looks like inline assembly doesn't work inside a structure. Have to see if I can work around that...
Seems to work for me. Here's foo.cpp which compiles and runs:
class pin {
int thepin;
enum { DFLTPIN = 56, DFLTPIN2 = 57 };
void outlo() {
int x = thepin;
__asm {
drvl x
}
}
void outhi() {
int x = thepin;
__asm {
drvh x
}
}
void setpin(int x) {
thepin = x;
}
int getpin() { return thepin; }
} c;
int main()
{
c.setpin(c.DFLTPIN);
for(;;) {
c.outlo();
_waitx(20_000_000);
c.outhi();
_waitx(20_000_000);
}
return 0;
}
Thanks. I see now that I should have given that file a ".cpp" or ".c++" extension and used "class" instead of "struct" for converting a Spin object...
But, I think I'm happy with the way it worked out doing it the C way...
Your example works for me too, guess I did something wrong.
@Rayman said:
[...] and used "class" instead of "struct" for converting a Spin object...
Not sure how FlexC does it, but in standard C++, you can use either struct or class, the only difference is the default visibility of members (public for struct, private for class).
Using the $-1 like this in inline assembly doesn't seem to work if_nc jmp $-1
I don't know the rules for inline assembly, but in normal assembly you need to used the "#" character for the jmp target. Also, you would use "jmp #$-1" to jump back to the previous instruction for cog code, and "jmp #$-4" for hub code. I'm guessing that inline assembly generates hub code.
Comments
At the moment there's probably not very much you can do to reduce COG usage. Breaking large functions/subroutines up into smaller ones might help, and of course if you have any code explicitly placed in COG you should move it to LUT or HUB. I'm working on making the COG space used selectable via the --fcache option, which will make it possible to tweak the space for your application.
@JRoark : I've posted an updated beta on Patreon that has a smaller default for the FCACHE area (so more COG ram available) and also the ability to specify a different the FCACHE area size on the command line.
Awesome! I’ll see how she flies in a bit. Thanks, Eric.
@ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:
I also discovered some "hidden" gems that are not documented in the FlexBASIC doc, but appear to work are look to be deriviatives of functions found in the general compiler docs. They are:
@ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:@ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:
Is that like the dog ate my homework?
Jim
Lol. Yep, pretty much. Except this is a 500 lb gully cat who answers to “Satan”.![:) :)](https://forums.parallax.com/resources/emoji/smile.png)
Warning: thread drift.
@ersmith Should C defines act line Spin2 constants in included .spin2 files?
I tried this:
#define VGA_BASEPIN 48
But, it says unknown symbol, so I'm guessing this doesn't work... Should/Can it?
Not a big deal either way. Just thought it would work...
No, for several reasons:
(1) Objects created in C with "struct __using" are like objects created with OBJ in Spin2. The constants in the top level file don't go down into the sub-objects; similarly, constants in the C file don't go into the objects either.
(2) #define is actually even weaker than constants in CON. A #define creates a macro where every occurance of the symbol is replaced with the text after it. So after
#define VGA_BASEPIN 48
the result is literally as if you did a search-and-replace inside the .c file and replaced every instance of VGA_BASEPIN with 48. It's a text substitution only, and only works within that specific file.Sorry for the delay, but I'm a bit too knackered under the week to get to my playtime stuff. But I just verified - works as advertised, thanks for the quick implementation! It seems the default is 230400, pnut allegedly uses 2_000_000. Just FYI if congruence is relevant to you here. Or the spin doc is wrong![:) :)](https://forums.parallax.com/resources/emoji/smile.png)
@ersmith On the subject of suggestions, I have two for your consideration:
__FLEXBASIC__
is defined as the compiler version (currently "5"). Could we change this (or create a new symbol) that includes the major, minor, revision, (ie, "5.4.0")?Sun 25Aug2021 12:34:56
or whatever format the standard C language uses?@JRoark : Those sound like good ideas, thanks. To get all 4 components of the version into the symbol it'll have to be a string rather than an integer, so I think I'll make a new symbol
__FLEXBASIC_VERSION__
for that.EDIT: Looks like there's already a
__VERSION__
symbol defined. I guess I forgot to document that, I'll add it to the manual.Should things like _rnd() also be in the manual? Or, should there be Propeller2.h manual that is separate?
I was also thinking about getting the time in there somehow... Maybe better with loadp2? Was thinking about an easy way to initialize a real time clock...
Yes, _rnd() should be documented. There's probably quite a lot of stuff missing from the documentation, sorry. Although I'm always happy to accept pull requests
.
As for time, not sure what the best approach to that is. Probably a new function call that communicates with the host via loadp2 to get the time, something like the existing file server. Is that the kind of thing you were thinking of?
Maybe Plan9 provides time already? If not directly, maybe I could create a new dummy file and then get the time from that file stats?
You're right, if you create a dummy file on the host and then do a stat() on it you could get the time that way. That's a nice idea, and saves having to add anything to loadp2.
Could FlexSpin please support/tolerate a colon at the end of a label?
One could then search for routine: without matching all the call #routine
PNut doesn't support this though, does it? I'm reluctant to introduce more incompatibilities with PNut, especially in the assembly language.
One work-around would be to use a capital letter in the actual label definition (like
Routine
) and lower case in the uses (call #routine
). Spin is case insensitive, so this should work in all assemblers.Is colon a valid character in a PASM2 label, in either PNut or FlexSpin? I can't run PNut and I need to use FlexSpin anyway as
#include
is vital.Changing the subject, is it possible to concatenate binary constants? E.g. if
a = %1011
andb = %0010
can I combine a and b to get%10110010
? This would be very handy for skip pattern bits.a and b are stored as 32 bit values internally, so leading 0's are lost. So no, you can't concatenate them, because once they're parsed there's no way to know how wide they're "supposed" to be.
Is there a way to access the values of an enum that is inside a structure in C?
I'm trying to replicate the way you this in Spin for CON values in a Spin object...
@Rayman ,
enum become defines so there use is just the value that is assigned.
enum {
five = 5,
six,
seven,
eight,
twelve = 12,
thirteen,
fourteen,
fifteen
} whatever;
Mike
I'm trying to replicate an I2C Spin code in C like this:
There doesn't seem to be a way to get to the PullupOptions values from outside the structure...
Was thinking this would work:
i2c_Port::PU_15K
But it doesn't...
I could leave them outside the structure, but it would be cleaner if they were inside...
I guess the above usage is C++ an so not going to work here...
Looks like inline assembly doesn't work inside a structure. Have to see if I can work around that...
Ok, maybe the above idea is just not a good idea...
Instead of making an I2C code structure, I'll do what other C I2C codes I've seen do and create a structure that just has port specific things like timing and pin #s in it.
That should make everything work better.
Not sure if this is a bug or not...
Using the $-1 like this in inline assembly doesn't seem to work
if_nc jmp $-1
Yes, in C enums are always global, this is part of the language spec so I can't change it. In C++ they can be part of classes though, and flexspin will use that semantics if the file ends in ".cpp" or ".c++"; then they can be accessed by something like "x.THE_CONSTANT".
Seems to work for me. Here's foo.cpp which compiles and runs:
Thanks. I see now that I should have given that file a ".cpp" or ".c++" extension and used "class" instead of "struct" for converting a Spin object...
But, I think I'm happy with the way it worked out doing it the C way...
Your example works for me too, guess I did something wrong.
Not sure how FlexC does it, but in standard C++, you can use either
struct
orclass
, the only difference is the default visibility of members (public for struct, private for class).Thanks @Wuerfel_21 , I suppose "struct" would be better for Spin conversions then.
I don't know the rules for inline assembly, but in normal assembly you need to used the "#" character for the jmp target. Also, you would use "jmp #$-1" to jump back to the previous instruction for cog code, and "jmp #$-4" for hub code. I'm guessing that inline assembly generates hub code.