Skip to content

Rewrite unicodeCodepointToUtf8 w/ bitopt#5625

Merged
NiLuJe merged 2 commits intokoreader:masterfrom
NiLuJe:master
Nov 22, 2019
Merged

Rewrite unicodeCodepointToUtf8 w/ bitopt#5625
NiLuJe merged 2 commits intokoreader:masterfrom
NiLuJe:master

Conversation

@NiLuJe
Copy link
Copy Markdown
Member

@NiLuJe NiLuJe commented Nov 22, 2019

Avoids costly divs & modulos


This change is Reviewable

Avoids costly divs & modulos
@NiLuJe
Copy link
Copy Markdown
Member Author

NiLuJe commented Nov 22, 2019

Random optimization because I noticed I had a copy of that in C lying around in FBInk ;p.

@NiLuJe
Copy link
Copy Markdown
Member Author

NiLuJe commented Nov 22, 2019

(We can't use the unsigned wraparound trickery from the first ref. for the surrogates test because Lua :/).

Copy link
Copy Markdown
Member

@Frenzie Frenzie left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@poire-z
Copy link
Copy Markdown
Contributor

poire-z commented Nov 22, 2019

For info: https://luapower.com/luajit-notes

  • multiplications and additions are cheaper than memory access, so storing the results of these operations in temporary variables might actually harm performance (more register spills).
  • divisions are 4x slower than multiplications on x86, so when dividing by a constant, it helps turning x / c into x * (1 / c) since the constant expression is folded -- LuaJIT does this already for power-of-2 constants where the semantics are equivalent.
  • the % operator is slow (it's implemented in terms of math.floor() and division) and really kills hot loops; math.fmod() is even slower; I don't have a solution for this except for x % powers-of-two which can be computed with bit ops.

@NiLuJe NiLuJe merged commit e0f14a3 into koreader:master Nov 22, 2019
@robert00s robert00s added this to the 2019.12 milestone Nov 23, 2019
mwoz123 pushed a commit to mwoz123/koreader that referenced this pull request Mar 29, 2020
* Rewrite unicodeCodepointToUtf8 w/ bitopt

Avoids costly divs & modulos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants