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
Recent
TSaveDialog and OneDrive
by
Zvoni
[
Today
at 08:57:08 am]
RunFormula: math expressi...
by
CM630
[
Today
at 08:21:49 am]
TCHATGPT — An Artificial ...
by
Weiss
[
Today
at 07:00:13 am]
You can embed Windows Con...
by
Ozz_Nixon
[
Today
at 03:39:13 am]
[New Component] ExtTabCtr...
by
jianwt
[
Today
at 02:48:15 am]
Implementing an Elo ratin...
by
mas steindorff
[
Today
at 12:55:07 am]
FPC Unleashed (inline var...
by
440bx
[June 16, 2026, 11:53:51 pm]
Codepage issue in console...
by
ASerge
[June 16, 2026, 11:37:57 pm]
RFC: Separation of MCU an...
by
ackarwow
[June 16, 2026, 11:06:14 pm]
Error with last fixes_3.2...
by
patyit
[June 16, 2026, 09:49:02 pm]
Mundo Medieval 3D MMORPG ...
by
Rodrigo Robles
[June 16, 2026, 06:06:17 pm]
Which Control should I us...
by
wp
[June 16, 2026, 05:08:55 pm]
Just Question App paramet...
by
eldonfsr
[June 16, 2026, 04:50:19 pm]
Pdf Viewer in Pascal
by
Handoko
[June 16, 2026, 03:55:42 pm]
Content is distorting / w...
by
Handoko
[June 16, 2026, 03:53:02 pm]
ZxTune chiptunes player
by
Guva
[June 16, 2026, 12:41:14 pm]
Onscroll event for Tscrol...
by
laz_one_or2
[June 16, 2026, 11:16:39 am]
Fpcupdeluxe
by
CharlyTango
[June 16, 2026, 10:35:33 am]
Compiling Qt6 project on ...
by
wp
[June 16, 2026, 10:14:53 am]
What am I missing here? [...
by
loaded
[June 16, 2026, 08:11:06 am]
IDE Editor (OS: Windows11...
by
keith
[June 16, 2026, 07:36:18 am]
Single and Double, Conver...
by
avk
[June 16, 2026, 06:55:03 am]
AI Assist Python - to - P...
by
kirtu
[June 16, 2026, 12:57:01 am]
Instruction-level paralle...
by
LeP
[June 16, 2026, 12:23:51 am]
Lazarus syntax helpers
by
Edson
[June 15, 2026, 10:34:34 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [CLOSED] Optimization at function TFPReaderBMP.ShiftCount (Read 1242 times)
lagprogramming
Sr. Member
Posts: 409
[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: 3400
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: 227
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: 2715
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