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
activex.pp definition pro...
by
Thaddy
[
Today
at 06:54:30 am]
Converting excel to csv -...
by
Thaddy
[
Today
at 06:46:21 am]
Feature request: hard typ...
by
Thaddy
[
Today
at 06:42:55 am]
Compiler don't know the S...
by
Thaddy
[
Today
at 06:38:35 am]
Lazarus IDE crashes ( Due...
by
Thaddy
[
Today
at 06:11:56 am]
My DIY dynamic array occu...
by
Thaddy
[
Today
at 06:06:50 am]
Forte Report CE Questions
by
PascalProg
[
Today
at 01:32:42 am]
Canvas.PolyBezier
by
wp
[
Today
at 12:16:24 am]
InstallAware 2025 Sources...
by
msintle
[July 07, 2025, 11:49:05 pm]
[SOLVED] Lazarus IDE 4 UI...
by
Psacla_63
[July 07, 2025, 11:03:06 pm]
Conant Fractal (Close to ...
by
Boleeman
[July 07, 2025, 10:38:58 pm]
problem with certain char...
by
tetrastes
[July 07, 2025, 09:22:02 pm]
controls.lpr(731,15) Erro...
by
tetrastes
[July 07, 2025, 08:55:04 pm]
Trouble compiling fpc for...
by
ermok
[July 07, 2025, 08:17:48 pm]
MDI ChildForm
by
Remy Lebeau
[July 07, 2025, 07:59:10 pm]
Fast Canvas Library V1.05...
by
Lulu
[July 07, 2025, 07:58:57 pm]
Library for drawing a pat...
by
gidesa
[July 07, 2025, 07:43:59 pm]
Sutcliffe Fractal: Anothe...
by
Joanna
[July 07, 2025, 02:16:29 pm]
Billowing Flower: A Tenta...
by
Joanna
[July 07, 2025, 02:13:22 pm]
Spiral Mandala Patterns o...
by
Boleeman
[July 07, 2025, 01:56:56 pm]
definition problem in act...
by
marcov
[July 07, 2025, 01:52:12 pm]
Snaking Triangle Animatio...
by
Boleeman
[July 07, 2025, 01:49:02 pm]
FPC 3.2.2 - non Alpha Nam...
by
MarkMLl
[July 07, 2025, 01:29:04 pm]
[SOLVED] How to query the...
by
rvk
[July 07, 2025, 12:36:25 pm]
FPSpreadsheet v2.0 releas...
by
LV
[July 07, 2025, 12:34:38 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [CLOSED] Optimization at function TFPReaderBMP.ShiftCount (Read 1066 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