Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
821bc6d7
Commit
821bc6d7
authored
Feb 12, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
system/ByteOrder: use GCC built-ins if available
parent
6e66a5b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
6 deletions
+38
-6
ByteOrder.hxx
src/system/ByteOrder.hxx
+38
-6
No files found.
src/system/ByteOrder.hxx
View file @
821bc6d7
/*
* Copyright (C) 2011-201
3
Max Kellermann <max@duempel.org>,
* Copyright (C) 2011-201
5
Max Kellermann <max@duempel.org>,
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -30,6 +30,8 @@
#ifndef BYTE_ORDER_HXX
#define BYTE_ORDER_HXX
#include "Compiler.h"
#include <stdint.h>
#if defined(__i386__) || defined(__x86_64__) || defined(__ARMEL__)
...
...
@@ -75,23 +77,53 @@ IsBigEndian()
}
static
inline
constexpr
uint16_t
GenericByteSwap16
(
uint16_t
value
)
{
return
(
value
>>
8
)
|
(
value
<<
8
);
}
static
inline
constexpr
uint32_t
GenericByteSwap32
(
uint32_t
value
)
{
return
(
value
>>
24
)
|
((
value
>>
8
)
&
0x0000ff00
)
|
((
value
<<
8
)
&
0x00ff0000
)
|
(
value
<<
24
);
}
static
inline
constexpr
uint64_t
GenericByteSwap64
(
uint64_t
value
)
{
return
uint64_t
(
GenericByteSwap32
(
uint32_t
(
value
>>
32
)))
|
(
uint64_t
(
GenericByteSwap32
(
value
))
<<
32
);
}
static
inline
constexpr
uint16_t
ByteSwap16
(
uint16_t
value
)
{
return
(
value
>>
8
)
|
(
value
<<
8
);
#if CLANG_OR_GCC_VERSION(4,8)
return
__builtin_bswap16
(
value
);
#else
return
GenericByteSwap16
(
value
);
#endif
}
static
inline
constexpr
uint32_t
ByteSwap32
(
uint32_t
value
)
{
return
(
value
>>
24
)
|
((
value
>>
8
)
&
0x0000ff00
)
|
((
value
<<
8
)
&
0x00ff0000
)
|
(
value
<<
24
);
#if CLANG_OR_GCC_VERSION(4,3)
return
__builtin_bswap32
(
value
);
#else
return
GenericByteSwap32
(
value
);
#endif
}
static
inline
constexpr
uint64_t
ByteSwap64
(
uint64_t
value
)
{
return
uint64_t
(
ByteSwap32
(
uint32_t
(
value
>>
32
)))
|
(
uint64_t
(
ByteSwap32
(
value
))
<<
32
);
#if CLANG_OR_GCC_VERSION(4,3)
return
__builtin_bswap64
(
value
);
#else
return
GenericByteSwap64
(
value
);
#endif
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment