Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Free Pascal
»
FPC development
(Moderators:
FPK
,
Tomas Hajny
) »
[CLOSED] Optimization at function TFPReaderBMP.ShiftCount
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
WIKI Timeout issues
Please read here if you have trouble connecting to the wiki
Recent
LINUX: My program stops w...
by
n7800
[
Today
at 11:23:20 pm]
ChatGPT and ObjectPascal ...
by
PascalDragon
[
Today
at 11:22:21 pm]
controls.lpr(731,15) Erro...
by
Guser979
[
Today
at 11:22:13 pm]
[Solved] Reference to bsS...
by
Wilko500
[
Today
at 11:15:03 pm]
Questions about GUID decl...
by
PascalDragon
[
Today
at 11:10:00 pm]
TBufDataset with Invalid ...
by
talisjonatas
[
Today
at 11:06:24 pm]
Synapse TCP/IP client and...
by
rca
[
Today
at 10:46:14 pm]
activex.pp definition pro...
by
gues1
[
Today
at 10:27:36 pm]
Hint windows misplaced an...
by
n7800
[
Today
at 09:59:53 pm]
Input Chinese using Micro...
by
n7800
[
Today
at 09:49:38 pm]
internal Compiler Error
by
marcov
[
Today
at 09:25:27 pm]
Zeromemory vs. Fillchar
by
TBMan
[
Today
at 09:22:44 pm]
Persistent MacOS Arm M ch...
by
Grahame Grieve
[
Today
at 07:56:35 pm]
Flow fields and BFS
by
TBMan
[
Today
at 06:58:22 pm]
Create a png image from a...
by
thijsvandien
[
Today
at 06:53:41 pm]
Platform eXtended Library...
by
pascalbythree
[
Today
at 05:10:57 pm]
Tangled Line Pattern Make...
by
Boleeman
[
Today
at 04:27:51 pm]
DBF edit & append problem
by
Petrus Vorster
[
Today
at 04:08:21 pm]
[Solved] Can't install mo...
by
lainz
[
Today
at 03:28:41 pm]
[Solved]Open Project fail...
by
cdbc
[
Today
at 03:06:30 pm]
Popup Form to close when ...
by
Thaddy
[
Today
at 02:10:55 pm]
Spikey Splat Creatures fr...
by
Boleeman
[
Today
at 01:19:35 pm]
Amigo programming languag...
by
paxscript
[
Today
at 12:20:33 pm]
Ballet of Lines and Dots ...
by
Boleeman
[
Today
at 09:19:59 am]
Using icons in own open s...
by
paule32
[
Today
at 08:14:05 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [CLOSED] Optimization at function TFPReaderBMP.ShiftCount (Read 1069 times)
lagprogramming
Sr. Member
Posts: 407
[CLOSED] Optimization at function TFPReaderBMP.ShiftCount
«
on:
January 09, 2024, 12:43:16 pm »
packages/fcl-image/src/fpreadbmp.pp has
Code: Pascal
[Select]
[+]
[-]
function
TFPReaderBMP
.
ShiftCount
(
Mask
:
longword
)
:
shortint
;
var
tmp
:
shortint
;
begin
tmp
:
=
0
;
if
Mask
=
0
then
begin
Result
:
=
0
;
exit
;
end
;
while
(
Mask
mod
2
)
=
0
do
{ rightmost bit is 0 }
begin
inc
(
tmp
)
;
Mask
:
=
Mask
shr
1
;
end
;
tmp
:
=
tmp
-
(
8
-
popcnt
(
byte
(
Mask
and
$FF
)
)
)
;
Result
:
=
tmp
;
end
;
The following patch replaces "
while (Mask mod 2)=0 do
" with the faster "
while (Mask and 1)=0 do
" line.
«
Last Edit: January 10, 2024, 10:29:39 am by lagprogramming
»
Logged
Zvoni
Hero Member
Posts: 3001
Re: Optimization at function TFPReaderBMP.ShiftCount
«
Reply #1 on:
January 09, 2024, 01:04:49 pm »
Addition:
1) Line 16+17 can be coalesced into one line
2) Why use a tmp-var in the first place?
Logged
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
RayoGlauco
Full Member
Posts: 204
Beers: 1567
Re: Optimization at function TFPReaderBMP.ShiftCount
«
Reply #2 on:
January 09, 2024, 01:28:09 pm »
My own version may be like this (I agree Zvoni's opinion):
Code: Pascal
[Select]
[+]
[-]
function
TFPReaderBMP
.
ShiftCount
(
Mask
:
longword
)
:
shortint
;
begin
Result
:
=
0
;
if
Mask
=
0
then
exit
;
while
(
Mask
and
1
)
=
0
do
{ rightmost bit is 0 }
begin
inc
(
Result
)
;
Mask
:
=
Mask
shr
1
;
end
;
Result
:
=
Result
-
(
8
-
popcnt
(
byte
(
Mask
and
$FF
)
)
)
;
end
;
«
Last Edit: January 09, 2024, 01:34:42 pm by RayoGlauco
»
Logged
To err is human, but to really mess things up, you need a computer.
AlexTP
Hero Member
Posts: 2577
Re: [CLOSED] Optimization at function TFPReaderBMP.ShiftCount
«
Reply #3 on:
January 10, 2024, 03:49:21 pm »
Posted and applied:
https://gitlab.com/freepascal.org/fpc/source/-/issues/40590
Logged
CudaText editor
-
ATSynEdit
-
More from me
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Free Pascal
»
FPC development
(Moderators:
FPK
,
Tomas Hajny
) »
[CLOSED] Optimization at function TFPReaderBMP.ShiftCount
TinyPortal
© 2005-2018