Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Free Pascal
»
FPC development
(Moderators:
FPK
,
Tomas Hajny
) »
x64 SwapEndian(<16bit>) via ROL is faster?
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
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Interesting article about...
by
Joanna from IRC
[
Today
at 01:21:28 am]
had a question and found ...
by
MarkMLl
[
Today
at 12:13:40 am]
DBLookupListBox shows (ME...
by
Sieben
[December 10, 2024, 11:10:25 pm]
Random errors in TensorFl...
by
TRon
[December 10, 2024, 11:02:08 pm]
Online tutor using remote...
by
silvercoder70
[December 10, 2024, 10:04:11 pm]
how to control the order ...
by
mas steindorff
[December 10, 2024, 08:47:04 pm]
Wiki, a dead link in page...
by
d7_2_laz
[December 10, 2024, 08:42:35 pm]
How to save a Graphic fro...
by
jeremiah
[December 10, 2024, 08:11:54 pm]
Crosshair error when chan...
by
Marq01
[December 10, 2024, 08:02:17 pm]
Adding interfaces to any ...
by
Thaddy
[December 10, 2024, 07:32:56 pm]
AVRPascal – free code edi...
by
ackarwow
[December 10, 2024, 04:57:47 pm]
MainMenu: How to use the ...
by
madref
[December 10, 2024, 04:19:32 pm]
SAVE StringGrid to PDF
by
dseligo
[December 10, 2024, 04:13:22 pm]
I need advice for a new c...
by
wp
[December 10, 2024, 03:18:11 pm]
Controlled Folder Access
by
Igor Kokarev
[December 10, 2024, 02:17:46 pm]
Datatypes Interoperabilit...
by
silvercoder70
[December 10, 2024, 01:32:48 pm]
Notepad++ plugin with doc...
by
d7_2_laz
[December 10, 2024, 01:11:52 pm]
ZDataset.Locate + loParti...
by
silvercoder70
[December 10, 2024, 10:49:08 am]
SQLite3 Date Problem
by
silvercoder70
[December 10, 2024, 10:08:07 am]
Record "inheritance"/stru...
by
Thaddy
[December 10, 2024, 09:54:38 am]
D2Bridge Framework for La...
by
egsuh
[December 10, 2024, 04:48:02 am]
Application deployment
by
cousinp
[December 10, 2024, 04:28:36 am]
[SOLVED] FPSpreadSheet, ...
by
TRon
[December 10, 2024, 01:25:51 am]
Is it possible to do git ...
by
TRon
[December 10, 2024, 12:41:39 am]
Draw Transparent Fill Rec...
by
LBox
[December 10, 2024, 12:00:51 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: x64 SwapEndian(<16bit>) via ROL is faster? (Read 1386 times)
AlexTP
Hero Member
Posts: 2488
x64 SwapEndian(<16bit>) via ROL is faster?
«
on:
September 08, 2023, 03:58:21 pm »
This page suggests to do SwapEndian via ROL
https://stackoverflow.com/questions/3065335/how-to-convert-big-endian-numbers-to-native-numbers-delphi
Code: Pascal
[Select]
[+]
[-]
function
SwapEndian16
(
Value
:
smallint
)
:
smallint
;
register
;
asm
rol ax
,
8
end
;
and we now have this in rtl/x86_64/x86_64.inc
Code: Pascal
[Select]
[+]
[-]
{ SwapEndian(<16 Bit>) being inlined is faster than using assembler }
function
SwapEndian
(
const
AValue
:
SmallInt
)
:
SmallInt
;
{$ifdef SYSTEMINLINE}inline;{$endif}
begin
{ the extra Word type cast is necessary because the "AValue shr 8" }
{ is turned into "longint(AValue) shr 8", so if AValue < 0 then }
{ the sign bits from the upper 16 bits are shifted in rather than }
{ zeroes. }
Result
:
=
SmallInt
(
(
(
Word
(
AValue
)
shr
8
)
or
(
Word
(
AValue
)
shl
8
)
)
and
$ffff
)
;
end
;
function
SwapEndian
(
const
AValue
:
Word
)
:
Word
;
{$ifdef SYSTEMINLINE}inline;{$endif}
begin
Result
:
=
(
(
AValue
shr
8
)
or
(
AValue
shl
8
)
)
and
$ffff
;
end
;
Which is faster?
«
Last Edit: September 08, 2023, 04:05:48 pm by AlexTP
»
Logged
CudaText editor
-
ATSynEdit
-
More from me
birin
New member
Posts: 9
Re: x64 SwapEndian(<16bit>) via ROL is faster?
«
Reply #1 on:
September 08, 2023, 04:35:23 pm »
If SwapEndian16 are not inlined, then she needs CALL and RET.
Instruction flow interruption is time consuming.
I think the second version of SwapEndian doesn't need the and $ffff because all values are Word, and Word are unsigned.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Free Pascal
»
FPC development
(Moderators:
FPK
,
Tomas Hajny
) »
x64 SwapEndian(<16bit>) via ROL is faster?
TinyPortal
© 2005-2018