Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenlib/BLI_endian_switch_inline.h12
-rw-r--r--source/blender/blenlib/intern/endian_switch.c24
2 files changed, 20 insertions, 16 deletions
diff --git a/source/blender/blenlib/BLI_endian_switch_inline.h b/source/blender/blenlib/BLI_endian_switch_inline.h
index 358206f1177..f5f0e59cfa8 100644
--- a/source/blender/blenlib/BLI_endian_switch_inline.h
+++ b/source/blender/blenlib/BLI_endian_switch_inline.h
@@ -42,9 +42,13 @@ BLI_INLINE void BLI_endian_switch_int16(short *val)
}
BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val)
{
+#ifdef __GNUC__
+ *val = __builtin_bswap16(*val);
+#else
unsigned short tval = *val;
*val = (tval >> 8) |
(tval << 8);
+#endif
}
@@ -55,11 +59,15 @@ BLI_INLINE void BLI_endian_switch_int32(int *val)
}
BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val)
{
+#ifdef __GNUC__
+ *val = __builtin_bswap32(*val);
+#else
unsigned int tval = *val;
*val = ((tval >> 24)) |
((tval << 8) & 0x00ff0000) |
((tval >> 8) & 0x0000ff00) |
((tval << 24));
+#endif
}
BLI_INLINE void BLI_endian_switch_float(float *val)
{
@@ -74,6 +82,9 @@ BLI_INLINE void BLI_endian_switch_int64(int64_t *val)
}
BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val)
{
+#ifdef __GNUC__
+ *val = __builtin_bswap16(*val);
+#else
uint64_t tval = *val;
*val = ((tval >> 56)) |
((tval << 40) & 0x00ff000000000000ll) |
@@ -83,6 +94,7 @@ BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val)
((tval >> 24) & 0x0000000000ff0000ll) |
((tval >> 40) & 0x000000000000ff00ll) |
((tval << 56));
+#endif
}
BLI_INLINE void BLI_endian_switch_double(double *val)
{
diff --git a/source/blender/blenlib/intern/endian_switch.c b/source/blender/blenlib/intern/endian_switch.c
index 892d7396011..b1dcdffba01 100644
--- a/source/blender/blenlib/intern/endian_switch.c
+++ b/source/blender/blenlib/intern/endian_switch.c
@@ -32,9 +32,8 @@ void BLI_endian_switch_int16_array(short *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_int16(val--);
+ BLI_endian_switch_int16(val++);
}
}
}
@@ -43,9 +42,8 @@ void BLI_endian_switch_uint16_array(unsigned short *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_uint16(val--);
+ BLI_endian_switch_uint16(val++);
}
}
}
@@ -54,9 +52,8 @@ void BLI_endian_switch_int32_array(int *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_int32(val--);
+ BLI_endian_switch_int32(val++);
}
}
}
@@ -65,9 +62,8 @@ void BLI_endian_switch_uint32_array(unsigned int *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_uint32(val--);
+ BLI_endian_switch_uint32(val++);
}
}
}
@@ -76,9 +72,8 @@ void BLI_endian_switch_float_array(float *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_float(val--);
+ BLI_endian_switch_float(val++);
}
}
}
@@ -87,9 +82,8 @@ void BLI_endian_switch_int64_array(int64_t *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_int64(val--);
+ BLI_endian_switch_int64(val++);
}
}
}
@@ -98,9 +92,8 @@ void BLI_endian_switch_uint64_array(uint64_t *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_uint64(val--);
+ BLI_endian_switch_uint64(val++);
}
}
}
@@ -110,9 +103,8 @@ void BLI_endian_switch_double_array(double *val, const int size)
{
if (size > 0) {
int i = size;
- val = val + (size - 1);
while (i--) {
- BLI_endian_switch_double(val--);
+ BLI_endian_switch_double(val++);
}
}
}