Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StrawData: inefficient read implementations #2

Open
JonasKunze opened this issue Aug 11, 2014 · 0 comments
Open

StrawData: inefficient read implementations #2

JonasKunze opened this issue Aug 11, 2014 · 0 comments

Comments

@JonasKunze
Copy link
Member

Currently the StrawData constructor is reading the raw data fields into separate class variables (m_packetLength = readPacketLength()). The read methods are implemented in a very inefficient way (many branches instead of simple copy instructions). One should use a packed struct to directly access the fields. Something like following should do (I don't know the actual format, just guessing based on your code):

struct STRAW_DATA_HDR {
    uint16_t packetLength;
    uint8_t triggerTypeWord;
    uint8_t chamber:2;
    uint8_t view:2;
    uint8_t halfView:2;
    uint8_t reserved:2;
}__attribute__ ((__packed__));

To access the fields one can do following:

(STRAW_DATA_HDR*) hdr = static_cast<STRAW_DATA_HDR*>(dataPointer);
m_packetLength = hdr->packetLength;

This way you have one single instruction (but two lines of code) to read the packetLength field.

Instead of reading all fields in the constructor one could check if directly accessing the packed struct is really slower then caching them. At least one should use larger data types like uint_fast8_t if caching is useful for class variables that are used very often.

Another way would be to implement the read methods with something like following (untested):
m_L0TriggerDecision = static_cast<uint8_t>(dataPointer+2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant