Giter Site home page Giter Site logo

Type of index variables about fwprofile HOT 3 OPEN

pnp-software avatar pnp-software commented on July 22, 2024
Type of index variables

from fwprofile.

Comments (3)

pasetti avatar pasetti commented on July 22, 2024

The reason for the "signed char" choice was that, at least in some cases, I am using the value -1 to encode an invalid or not yet defined value.

I am not really worried about users wanting to define state machines with more than 127 states or procedures with more than 127 as I think that this would be very unlikely (and probably indicative of poor design choices -- one should never have such large state machines or procedures). In any cases, all types are defined through typedef and users, if they really wanted to, could extend the type of their variables.

The argument about speed and memory footprint is appreciated but I am not sure it is completely correct. I would imagine, for instance, that the state machine and procedure descriptors would become larger if we switch from "signed char" to "signed int" (I am assuming that the compiler would "pack" the data structures representing the descriptors).

One final point: when there was a trade-off between memory footprint and speed, I generally gave priority to minimizing memory footprint. The rationale for this choice is as follows. In most realistic scenarios, most of the CPU would be used by the application code which implements the actions and guards of the state machine and procedures. Hence, CPU optimization of the state machine and procedure code would only have a marginal impact on the overall CPU efficiency.

from fwprofile.

oppm avatar oppm commented on July 22, 2024

I agree on the memory footprint minimizing, as less code/data means much faster code because of caching.

Ok, if users are expected/allowed to update the data types, then it probably doesn't matter at all and this issue is obsolete.

Packing data does indeed save memory for the data, but not for the instructions accessing them. Say, you want to read one element in such a packed 8-bit array on a 32-bit processor. You would need, a) read the 32-bit value where the element is included, b) mask the other elements away, c) shift the value to the correct position. So, three instructions instead of only one when using 32-bit variables.
I did a small test with the Example 3 (example procedure provided in the fwprofile-editor). I compiled for sparc processor with optimization enabled (GR712RC) for signed int and signed char:
text data bss dec hex
56240 3048 2124 61412 efe4 signed char
55536 3064 2204 60804 ed84 signed int
As expected: memory usage for data goes up when using 32-bit index variables, while instructions go down.

from fwprofile.

artbody avatar artbody commented on July 22, 2024

Application: OLED Display , STM32L476 some switches, a rotary encoder and a big user menu with a lot of options.

I was running in the same problem
with 125 transitions it worked perfect
then i've to add a new part in the user menu
this gives 133 transitions .

/** Check that the SM is properly configured */
	if (FwSmCheckRec(smDesc) != smSuccess) {
		printf("The state machine FSMMAIN is NOT properly configured ... FAILURE\n");

in smDesc i found this error message
smUndefinedTransSrc

so i debugged this error message and came to this part
smDesc->errCode = smTooManyOutTrans;

and then i found this in FwSmConstands.h
typedef signed char FwSmCounterS1_t;

after changing it to signed int
typedef signed int FwSmCounterS1_t;
it works again - as expected perfect LOL

/** Type used for signed counters with a "short" range. */
//typedef signed char FwSmCounterS1_t;
/** If there are more then 127 transitions  uncomment */
typedef signed int FwSmCounterS1_t;

I agree with
oppm commented on 15 Nov 2016

memory usage for data goes up when using 32-bit index variables, while instructions go down.

from fwprofile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.