473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

bswap intrinsic

Is there an intrinsic to wrap the bswap x86 instruction. I have written a
function to do this with inline assembler but I am wondering if an intrinsic
wouldn't be a better solution.

Regards,

George.
Nov 17 '05 #1
3 3946
George M. Garner Jr. wrote:
Is there an intrinsic to wrap the bswap x86 instruction. I have
written a function to do this with inline assembler but I am
wondering if an intrinsic wouldn't be a better solution.


it would be. AFIAK there is no such intrinsic.

-cd
Nov 17 '05 #2
_byteswap_ulong
_byteswap_uint64

Both in current Whidbey builds.

#include <intrin.h>

int main()

{

volatile unsigned long l = 1;

volatile unsigned long long ll = 1;

l = _byteswap_ulong(l);

ll = _byteswap_uint64(ll);

}

in a release build gives you

PUBLIC _main

; Function compile flags: /Ogtpy

; File d:\documents and settings\ronaldl\my documents\visual studio
2005\projects\byteswap\byteswap.cpp

; COMDAT _main

_TEXT SEGMENT

_l$ = -12 ; size = 4

_ll$ = -8 ; size = 8

_main PROC ; COMDAT

; 8 : {

sub esp, 12 ; 0000000cH

; 9 : volatile unsigned long l = 1;

mov eax, 1

mov DWORD PTR _l$[esp+12], eax

; 10 : volatile unsigned long long ll = 1;

mov DWORD PTR _ll$[esp+12], eax

mov DWORD PTR _ll$[esp+16], 0

; 11 :

; 12 : l = _byteswap_ulong(l);

mov eax, DWORD PTR _l$[esp+12]

bswap eax

mov DWORD PTR _l$[esp+12], eax

; 13 : ll = _byteswap_uint64(ll);

mov ecx, DWORD PTR _ll$[esp+12]

mov edx, DWORD PTR _ll$[esp+16]

bswap edx

bswap ecx

mov DWORD PTR _ll$[esp+12], edx

mov DWORD PTR _ll$[esp+16], ecx

; 14 : }

xor eax, eax

add esp, 12 ; 0000000cH

ret 0

_main ENDP

_TEXT ENDS

END

Or for X64 which has a quadword bswap instruction:

Function compile flags: /Ogtpy

; File d:\documents and settings\ronaldl\my documents\visual studio
2005\projects\byteswap\byteswap.cpp

; COMDAT main

_TEXT SEGMENT

l$ = 8

ll$ = 16

main PROC ; COMDAT

; 9 : volatile unsigned long l = 1;

mov DWORD PTR l$[rsp], 1

; 10 : volatile unsigned long long ll = 1;

mov QWORD PTR ll$[rsp], 1

; 11 :

; 12 : l = _byteswap_ulong(l);

mov eax, DWORD PTR l$[rsp]

bswap eax

mov DWORD PTR l$[rsp], eax

; 13 : ll = _byteswap_uint64(ll);

mov rax, QWORD PTR ll$[rsp]

bswap rax

mov QWORD PTR ll$[rsp], rax

; 14 : }

xor eax, eax

ret 0

main ENDP

_TEXT ENDS

END

Ronald Laeremans
Visual C++ team

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:eI**************@TK2MSFTNGP09.phx.gbl...
George M. Garner Jr. wrote:
Is there an intrinsic to wrap the bswap x86 instruction. I have
written a function to do this with inline assembler but I am
wondering if an intrinsic wouldn't be a better solution.


it would be. AFIAK there is no such intrinsic.

-cd

Nov 17 '05 #3
Great news Ron! Keep up the good work.

Regards,

George.
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
_byteswap_ulong
_byteswap_uint64

Both in current Whidbey builds.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Glenn Venzke | last post by:
I'm trying to write/compile a class that (1) accesses all the intrinsic ASP.NET objects (2) Uses Server.Transfer to redirect a user back to a log in page if a session has expired. I've gotten...
5
by: Jeremy Cowles | last post by:
I have been reading a book that focuses on understanding the intrinsic types of C++ in depth. The author's mentality is this: "Understand the intrinsic types, then learn the std types as needed...
13
by: Alek Davis | last post by:
Hi, Is it possible to access intrinsic ASP objects, such as Request, from a .NET class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can this library retrieve the request info...
7
by: A Traveler | last post by:
Hello all, i was just curious if anyone whos been playing with VS2005 could tell me... In javascript (and java??) you can alter the prototypes for an object in your project. I dont remember...
0
by: albean | last post by:
I I have a number of VB COM components used in ASP pages that access some intrinsic ASP objects. Basically we would get the context from COMSVCSLib and from there get the ASP Request and Response...
2
by: jason | last post by:
hello everyone, i have had a suppot ticket open with microsoft for some time to investigate a memory leak issue we are experiencing on our production web servers. the web servers host both ASP...
8
by: Thelma Lubkin | last post by:
I have finally nagged more work out of the non-profit organization that I'm trying to do volunteer work for. The following code begins a tiny form that is part of the project that I'll be...
19
by: docschnipp | last post by:
Hi, as someone pulling to C# over from C++ I stumbled over something today for which I was not able to find an answer: HOW do I convert a byte block with a given endianess to an int32 and vice...
2
by: Bryan Parkoff | last post by:
Do you know where I can find a good book how to write intrinsic function? Intrinsic function is useful to use MMX or SSE or any SIMD instruction of x86 and other machines for best portability. It...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.