ObjFW  Check-in [ffdba49764]

Overview
Comment:Add +[OFSystemInfo supportsAltiVec]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ffdba4976460ff648ca3f6f2a7c387fbb85258e379b87b8333b9fa5cdfa5ddfe
User & Date: js on 2015-10-17 17:27:21
Other Links: manifest | tags
Context
2015-10-17
19:47
configure: Use -integrated-as on Clang/MIPS check-in: 47ddf24d41 user: js tags: trunk
17:27
Add +[OFSystemInfo supportsAltiVec] check-in: ffdba49764 user: js tags: trunk
15:06
Fix a missing include check-in: 2e73c5fb65 user: js tags: trunk
Changes

Modified src/OFSystemInfo.h from [b1b706eed5] to [36a7138c5d].

180
181
182
183
184
185
186













187
188
189
 *
 * @note This method is only available on x86 and x86_64.
 *
 * @return Whether the CPU supports AVX2
 */
+ (bool)supportsAVX2;
#endif













@end

OF_ASSUME_NONNULL_END







>
>
>
>
>
>
>
>
>
>
>
>
>



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
 *
 * @note This method is only available on x86 and x86_64.
 *
 * @return Whether the CPU supports AVX2
 */
+ (bool)supportsAVX2;
#endif

#ifdef OF_PPC_ASM
/*!
 * @brief Returns whether the CPU supports AltiVec.
 *
 * @warning This method only checks CPU support and assumes OS support!
 *
 * @note This method is only available on PowerPC.
 *
 * @return Whether the CPU supports AltiVec
 */
+ (bool)supportsAltiVec;
#endif
@end

OF_ASSUME_NONNULL_END

Modified src/OFSystemInfo.m from [df1cd50578] to [77d1af34d2].

42
43
44
45
46
47
48



49
50
51
52
53
54
55
56
57




58
59
60
61
62
63
64
#endif
#ifdef __HAIKU__
# include <FindDirectory.h>
#endif
#ifdef __QNX__
# include <sys/syspage.h>
#endif




#if defined(OF_X86_64_ASM) || defined(OF_X86_ASM)
struct x86_regs {
	uint32_t eax, ebx, ecx, edx;
};
#endif

static size_t pageSize;
static size_t numberOfCPUs;





#if defined(OF_X86_64_ASM)
static OF_INLINE struct x86_regs OF_CONST_FUNC
x86_cpuid(uint32_t eax, uint32_t ecx)
{
	struct x86_regs regs;








>
>
>









>
>
>
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#endif
#ifdef __HAIKU__
# include <FindDirectory.h>
#endif
#ifdef __QNX__
# include <sys/syspage.h>
#endif
#ifdef OF_PPC_ASM
# include <setjmp.h>
#endif

#if defined(OF_X86_64_ASM) || defined(OF_X86_ASM)
struct x86_regs {
	uint32_t eax, ebx, ecx, edx;
};
#endif

static size_t pageSize;
static size_t numberOfCPUs;
#ifdef OF_PPC_ASM
static sig_atomic_t altiVecSupported;
static sigjmp_buf altiVecJumpBuffer;
#endif

#if defined(OF_X86_64_ASM)
static OF_INLINE struct x86_regs OF_CONST_FUNC
x86_cpuid(uint32_t eax, uint32_t ecx)
{
	struct x86_regs regs;

90
91
92
93
94
95
96
97









98














99
100
101
102
103
104
105
	    : "=a"(regs.eax), "=r"(regs.ebx), "=c"(regs.ecx), "=d"(regs.edx)
	    : "a"(eax), "c"(ecx)
	);

	return regs;
}
#endif










@implementation OFSystemInfo














+ (void)initialize
{
	if (self != [OFSystemInfo class])
		return;

#if defined(_WIN32)
	SYSTEM_INFO si;








>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
	    : "=a"(regs.eax), "=r"(regs.ebx), "=c"(regs.ecx), "=d"(regs.edx)
	    : "a"(eax), "c"(ecx)
	);

	return regs;
}
#endif

#ifdef OF_PPC_ASM
static void
altiVecSIGILLHandler(int signal)
{
	altiVecSupported = 0;
	siglongjmp(altiVecJumpBuffer, 1);
}
#endif

@implementation OFSystemInfo
#ifdef OF_PPC_ASM
+ (void)load
{
	altiVecSupported = 1;
	if (sigsetjmp(altiVecJumpBuffer, 1) == 0) {
		signal(SIGILL, altiVecSIGILLHandler);
		__asm__ __volatile__ (
		    "vor	v0, v0, v0"
		);
	}
	signal(SIGILL, SIG_DFL);
}
#endif

+ (void)initialize
{
	if (self != [OFSystemInfo class])
		return;

#if defined(_WIN32)
	SYSTEM_INFO si;
367
368
369
370
371
372
373







374
}

+ (bool)supportsAVX2
{
	return x86_cpuid(0, 0).eax >= 7 && (x86_cpuid(7, 0).ebx & (1 << 5));
}
#endif







@end







>
>
>
>
>
>
>

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
}

+ (bool)supportsAVX2
{
	return x86_cpuid(0, 0).eax >= 7 && (x86_cpuid(7, 0).ebx & (1 << 5));
}
#endif

#ifdef OF_PPC_ASM
+ (bool)supportsAltiVec
{
	return altiVecSupported;
}
#endif
@end