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

WString: Optimize a bit #7553

Merged
merged 4 commits into from
Nov 16, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cores/esp8266/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class String {
// if the initial value is null or invalid, or if memory allocation
// fails, the string will be marked as invalid (i.e. "if (s)" will
// be false).
String() {
String() __attribute__((always_inline)) { // See init()
init();
}
String(const char *cstr);
Expand Down Expand Up @@ -323,10 +323,16 @@ class String {
char *wbuffer() const { return isSSO() ? const_cast<char *>(sso.buff) : ptr.buff; } // Writable version of buffer

protected:
void init(void) {
sso.buff[0] = 0;
sso.len = 0;
sso.isHeap = 0;
void init(void) __attribute__((always_inline)) {
sso.buff[0] = 0; // In the Xtensa ISA, in fact, 32-bit store insn ("S32I.N") is one-byte shorter than 8-bit one ("S8I").
Copy link
Contributor

@TD-er TD-er Nov 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the comment; One byte or one bit shorter?
Or do you mean the generated binary code?

sso.buff[1] = 0; // Thanks to store-merging optimization, these 9 lines emit only 3 insns:
sso.buff[2] = 0; // "MOVI.N aX,0", "S32I.N aX,a2,0" and "S32I.N aX,a2,8" (6 bytes in total)
sso.buff[3] = 0;
sso.buff[8] = 0; // Unfortunately, GCC seems not to re-evaluate the cost of inlining after the store-merging optimizer stage,
sso.buff[9] = 0; // `always_inline` attribute is necessary in order to assure inlining.
sso.buff[10] = 0;
sso.len = 0;
sso.isHeap = 0;
}
void invalidate(void);
unsigned char changeBuffer(unsigned int maxStrLen);
Expand Down