ObjFW  Diff

Differences From Artifact [f063d53bfe]:

To Artifact [ad9b5b8288]:


10
11
12
13
14
15
16

17
18
19
20
21
22
23
 */

#ifndef OF_CONFIGURED
#error You are missing the ObjFW definitions!
#error Please use objfw-config!
#endif


#include <stdint.h>

#ifdef __GNUC__
#define OF_INLINE inline __attribute__((always_inline))
#define OF_LIKELY(cond) __builtin_expect(!!(cond), 1)
#define OF_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 */

#ifndef OF_CONFIGURED
#error You are missing the ObjFW definitions!
#error Please use objfw-config!
#endif

#include <stddef.h>
#include <stdint.h>

#ifdef __GNUC__
#define OF_INLINE inline __attribute__((always_inline))
#define OF_LIKELY(cond) __builtin_expect(!!(cond), 1)
#define OF_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else
40
41
42
43
44
45
46


47
48
49
50
51
52
53
#ifdef __GNUC__
#if defined(__amd64__) || defined(__x86_64__)
#define OF_AMD64_ASM
#elif defined(__i386__)
#define OF_X86_ASM
#elif defined(__ppc__) || defined(__PPC__)
#define OF_PPC_ASM


#endif
#endif

#define OF_BSWAP16_CONST(i)					\
	(((uint16_t)i & UINT16_C(0xFF00)) >> 8 |		\
	 ((uint16_t)i & UINT16_C(0x00FF)) << 8)
#define OF_BSWAP32_CONST(i)					\







>
>







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifdef __GNUC__
#if defined(__amd64__) || defined(__x86_64__)
#define OF_AMD64_ASM
#elif defined(__i386__)
#define OF_X86_ASM
#elif defined(__ppc__) || defined(__PPC__)
#define OF_PPC_ASM
#elif defined(__arm__) || defined(__ARM__)
#define OF_ARM_ASM
#endif
#endif

#define OF_BSWAP16_CONST(i)					\
	(((uint16_t)i & UINT16_C(0xFF00)) >> 8 |		\
	 ((uint16_t)i & UINT16_C(0x00FF)) << 8)
#define OF_BSWAP32_CONST(i)					\
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88


89
90
91
92
93
94
95
static OF_INLINE uint16_t
OF_BSWAP16(uint16_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
	asm("xchgb	%h0, %b0" : "=Q"(i) : "Q"(i));
#elif defined(OF_PPC_ASM)
	asm("lhbrx	%0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));


#else
	i = (i & UINT16_C(0xFF00)) >> 8 |
	    (i & UINT16_C(0x00FF)) << 8;
#endif
	return i;
}

static OF_INLINE uint32_t
OF_BSWAP32(uint32_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
	asm("bswap	%0" : "=q"(i) : "q"(i));
#elif defined(OF_PPC_ASM)
	asm("lwbrx	%0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));


#else
	i = (i & UINT32_C(0xFF000000)) >> 24 |
	    (i & UINT32_C(0x00FF0000)) >>  8 |
	    (i & UINT32_C(0x0000FF00)) <<  8 |
	    (i & UINT32_C(0x000000FF)) << 24;
#endif
	return i;







>
>














>
>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
static OF_INLINE uint16_t
OF_BSWAP16(uint16_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
	asm("xchgb	%h0, %b0" : "=Q"(i) : "Q"(i));
#elif defined(OF_PPC_ASM)
	asm("lhbrx	%0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));
#elif defined(OF_ARM_ASM)
	asm("rev16	%0, %0" : "=r"(i) : "0"(i));
#else
	i = (i & UINT16_C(0xFF00)) >> 8 |
	    (i & UINT16_C(0x00FF)) << 8;
#endif
	return i;
}

static OF_INLINE uint32_t
OF_BSWAP32(uint32_t i)
{
#if defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
	asm("bswap	%0" : "=q"(i) : "q"(i));
#elif defined(OF_PPC_ASM)
	asm("lwbrx	%0, 0, %1" : "=r"(i) : "r"(&i), "m"(i));
#elif defined(OF_ARM_ASM)
	asm("rev	%0, %0" : "=r"(i) : "0"(i));
#else
	i = (i & UINT32_C(0xFF000000)) >> 24 |
	    (i & UINT32_C(0x00FF0000)) >>  8 |
	    (i & UINT32_C(0x0000FF00)) <<  8 |
	    (i & UINT32_C(0x000000FF)) << 24;
#endif
	return i;