ObjFW  Check-in [1af54eb2c2]

Overview
Comment:Only align OFVector4D where necessary

Changing the alignment of OFVector4D globally (as was done previously)
would have technically been an ABI break in extremely rare cases.
However, since we only need the alignment for the methods added after
1.0, it's better to only have the alignment there and get back to full
ABI compatibility with 1.0.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1af54eb2c2dabfc7115810159f4ba65cc8d33ea67974af6e5cd7d6e9ef15f96b
User & Date: js on 2024-04-02 03:21:12
Other Links: manifest | tags
Context
2024-04-02
21:58
Fix a linker warning on macOS check-in: a6e2670136 user: js tags: trunk
03:21
Only align OFVector4D where necessary check-in: 1af54eb2c2 user: js tags: trunk
02:22
OFLocale: Support automatic initialization check-in: e7a8f3d462 user: js tags: trunk
Changes

Modified src/OFMatrix4x4.h from [e3aa63e106] to [06311cf4f1].

89
90
91
92
93
94
95





96
97
98
99
100
101
102
 * @param vector The vector to transform
 * @return The transformed vector
 */
- (OFVector4D)transformedVector: (OFVector4D)vector;

/**
 * @brief Transforms the specified vectors in-place according to the matrix.





 *
 * @param vectors The vectors to transform
 * @param count The count of the specified vectors
 */
- (void)transformVectors: (OFVector4D *)vectors count: (size_t)count;
@end








>
>
>
>
>







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 * @param vector The vector to transform
 * @return The transformed vector
 */
- (OFVector4D)transformedVector: (OFVector4D)vector;

/**
 * @brief Transforms the specified vectors in-place according to the matrix.
 *
 * @warning Please note that the vectors must be 16 byte aligned! This is
 *	    required to allow SIMD optimizations. Passing a pointer to vectors
 *	    that are not 16 byte aligned will crash if SIMD optimizations are
 *	    enabled.
 *
 * @param vectors The vectors to transform
 * @param count The count of the specified vectors
 */
- (void)transformVectors: (OFVector4D *)vectors count: (size_t)count;
@end

Modified src/OFMatrix4x4.m from [67c177d7d9] to [0c5b86a89a].

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
	    }];
	[self multiplyWithMatrix: scale];
	[scale release];
}

- (OFVector4D)transformedVector: (OFVector4D)vector
{
	OFVector4D copy = vector;

	[self transformVectors: &copy count: 1];

	return copy;
}

- (void)transformVectors: (OFVector4D *)vectors count: (size_t)count







|







360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
	    }];
	[self multiplyWithMatrix: scale];
	[scale release];
}

- (OFVector4D)transformedVector: (OFVector4D)vector
{
	OF_ALIGN(16) OFVector4D copy = vector;

	[self transformVectors: &copy count: 1];

	return copy;
}

- (void)transformVectors: (OFVector4D *)vectors count: (size_t)count

Modified src/OFObject.h from [18f66eccc2] to [a1d249e5df].

345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
}

/**
 * @struct OFVector4D OFObject.h ObjFW/OFObject.h
 *
 * @brief A vector in 4D space.
 */
typedef struct OF_ALIGN(16) OF_BOXABLE OFVector4D {
	/** The x coordinate of the vector */
	float x;
	/** The y coordinate of the vector */
	float y;
	/** The z coordinate of the vector */
	float z;
	/** The w coordinate of the vector */







|







345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
}

/**
 * @struct OFVector4D OFObject.h ObjFW/OFObject.h
 *
 * @brief A vector in 4D space.
 */
typedef struct OF_BOXABLE OFVector4D {
	/** The x coordinate of the vector */
	float x;
	/** The y coordinate of the vector */
	float y;
	/** The z coordinate of the vector */
	float z;
	/** The w coordinate of the vector */

Modified src/macros.h from [1147a05908] to [d86f5f8b91].

98
99
100
101
102
103
104
105
106
107
108
109

110
111
112

113
114
115
116
117
118
119
# define OF_LIKELY(cond) (cond)
# define OF_UNLIKELY(cond) (cond)
# define OF_CONST_FUNC
# define OF_NO_RETURN_FUNC
# define OF_WEAK_REF(sym)
#endif

#ifdef __GNUC__
# define OF_ALIGN(alignment) __attribute__((__aligned__(alignment)))
#endif

#if __STDC_VERSION__ >= 201112L

# define OF_ALIGNOF(type) _Alignof(type)
# define OF_ALIGNAS(type) _Alignas(type)
#else

# define OF_ALIGNOF(type) __alignof__(type)
# define OF_ALIGNAS(type) OF_ALIGN(OF_ALIGNOF(type))
#endif

#ifdef __BIGGEST_ALIGNMENT__
# define OF_BIGGEST_ALIGNMENT __BIGGEST_ALIGNMENT__
#else







<
<
<
<

>



>







98
99
100
101
102
103
104




105
106
107
108
109
110
111
112
113
114
115
116
117
# define OF_LIKELY(cond) (cond)
# define OF_UNLIKELY(cond) (cond)
# define OF_CONST_FUNC
# define OF_NO_RETURN_FUNC
# define OF_WEAK_REF(sym)
#endif





#if __STDC_VERSION__ >= 201112L
# define OF_ALIGN(size) _Alignas(size)
# define OF_ALIGNOF(type) _Alignof(type)
# define OF_ALIGNAS(type) _Alignas(type)
#else
# define OF_ALIGN(size) __attribute__((__aligned__(size)))
# define OF_ALIGNOF(type) __alignof__(type)
# define OF_ALIGNAS(type) OF_ALIGN(OF_ALIGNOF(type))
#endif

#ifdef __BIGGEST_ALIGNMENT__
# define OF_BIGGEST_ALIGNMENT __BIGGEST_ALIGNMENT__
#else

Modified tests/OFMatrix4x4Tests.m from [25395304c9] to [5e35103519].

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	OTAssertEqual(point.y, 2.5);
	OTAssertEqual(point.z, 14);
	OTAssertEqual(point.w, 1);
}

- (void)testTransformVectorsCount
{
	OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }};

	[_matrix transformVectors: points count: 2];

	OTAssertEqual(points[0].x, 18);
	OTAssertEqual(points[0].y, 46);
	OTAssertEqual(points[0].z, 74);
	OTAssertEqual(points[0].w, 102);







|







145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	OTAssertEqual(point.y, 2.5);
	OTAssertEqual(point.z, 14);
	OTAssertEqual(point.w, 1);
}

- (void)testTransformVectorsCount
{
	OF_ALIGN(16) OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }};

	[_matrix transformVectors: points count: 2];

	OTAssertEqual(points[0].x, 18);
	OTAssertEqual(points[0].y, 46);
	OTAssertEqual(points[0].z, 74);
	OTAssertEqual(points[0].w, 102);