File tree 4 files changed +115
-1
lines changed
4 files changed +115
-1
lines changed Original file line number Diff line number Diff line change 11
11
12
12
#include <stdbool.h>
13
13
#include <stdint.h>
14
+ #include <immintrin.h>
14
15
15
16
static inline bool add_overflow (uint64_t value1 , uint64_t value2 , uint64_t * result ) {
16
17
#if has_builtin (__builtin_uaddll_overflow )
Original file line number Diff line number Diff line change 1
1
find_package (cmocka REQUIRED)
2
- cmocka_add_tests(zone-tests types.c include .c ip4.c time.c base32.c svcb.c syntax.c eui.c)
2
+ if (HAVE_WESTMERE)
3
+ set (sources ${sources} bits-westmere.c)
4
+ set_source_files_properties (bits-westmere.c PROPERTIES COMPILE_FLAGS "-march=westmere" )
5
+ endif ()
6
+ if (HAVE_HASWELL)
7
+ set (sources ${sources} bits-haswell.c)
8
+ set_source_files_properties (bits-haswell.c PROPERTIES COMPILE_FLAGS "-march=haswell" )
9
+ endif ()
10
+
11
+ cmocka_add_tests(zone-tests types.c include .c ip4.c time.c base32.c svcb.c syntax.c eui.c ${sources} )
3
12
4
13
target_link_libraries (zone-tests PRIVATE zone)
5
14
target_sources (zone-tests PRIVATE tools.c)
Original file line number Diff line number Diff line change
1
+ /*
2
+ * bits-haswell.c -- test Haswell specific bit manipulation instructions
3
+ *
4
+ * Copyright (c) 2024, NLnet Labs. All rights reserved.
5
+ *
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ *
8
+ */
9
+ #include <stdarg.h>
10
+ #include <setjmp.h>
11
+ #include <string.h>
12
+ #include <cmocka.h>
13
+
14
+ #include "attributes.h"
15
+ #include "haswell/bits.h"
16
+
17
+ /*!cmocka */
18
+ void haswell_trailing_zeroes (void * * state )
19
+ {
20
+ (void )state ;
21
+ for (uint64_t shift = 0 ; shift < 63 ; shift ++ ) {
22
+ uint64_t bit = 1llu << shift ;
23
+ uint64_t tz = trailing_zeroes (bit );
24
+ assert_int_equal (tz , shift );
25
+ }
26
+ }
27
+
28
+ /*!cmocka */
29
+ void haswell_leading_zeroes (void * * state )
30
+ {
31
+ (void )state ;
32
+ for (uint64_t shift = 0 ; shift << 63 ; shift ++ ) {
33
+ const uint64_t bit = 1llu << shift ;
34
+ uint64_t lz = leading_zeroes (bit );
35
+ assert_int_equal (lz , 63 - shift );
36
+ }
37
+ }
38
+
39
+ /*!cmocka */
40
+ void haswell_prefix_xor (void * * state )
41
+ {
42
+ (void )state ;
43
+ // "0001 0001 0000 0101 0000 0110 0000 0000"
44
+ const uint64_t mask = 0x11050600llu ;
45
+ // "0001 1110 0000 0110 0000 0100 0000 0000"
46
+ const uint64_t xor_mask = 0x1E060400llu ;
47
+
48
+ assert_int_equal (prefix_xor (mask ), xor_mask );
49
+ }
50
+
51
+ /*!cm ocka */
52
+ // add_overflow
Original file line number Diff line number Diff line change
1
+ /*
2
+ * bits-westmere.c -- test Westmere specific bit manipulation instructions
3
+ *
4
+ * Copyright (c) 2024, NLnet Labs. All rights reserved.
5
+ *
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ *
8
+ */
9
+ #include <stdarg.h>
10
+ #include <setjmp.h>
11
+ #include <string.h>
12
+ #include <cmocka.h>
13
+
14
+ #include "attributes.h"
15
+ #include "westmere/bits.h"
16
+
17
+ /*!cmocka */
18
+ void westmere_trailing_zeroes (void * * state )
19
+ {
20
+ (void )state ;
21
+ for (uint64_t shift = 0 ; shift < 63 ; shift ++ ) {
22
+ uint64_t bit = 1llu << shift ;
23
+ uint64_t tz = trailing_zeroes (bit );
24
+ assert_int_equal (tz , shift );
25
+ }
26
+ }
27
+
28
+ /*!cmocka */
29
+ void westmere_leading_zeroes (void * * state )
30
+ {
31
+ (void )state ;
32
+ for (uint64_t shift = 0 ; shift << 63 ; shift ++ ) {
33
+ const uint64_t bit = 1llu << shift ;
34
+ uint64_t lz = leading_zeroes (bit );
35
+ assert_int_equal (lz , 63 - shift );
36
+ }
37
+ }
38
+
39
+ /*!cmocka */
40
+ void westmere_prefix_xor (void * * state )
41
+ {
42
+ (void )state ;
43
+ // "0001 0001 0000 0101 0000 0110 0000 0000"
44
+ const uint64_t mask = 0x11050600llu ;
45
+ // "0001 1110 0000 0110 0000 0100 0000 0000"
46
+ const uint64_t xor_mask = 0x1E060400llu ;
47
+
48
+ assert_int_equal (prefix_xor (mask ), xor_mask );
49
+ }
50
+
51
+ /*!cm ocka */
52
+ // add_overflow
You can’t perform that action at this time.
0 commit comments