-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcopytest.c
94 lines (77 loc) · 2.01 KB
/
copytest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//#include <stdlib.h>
//#include <stdio.h>
//#include <string.h>
//#include "compiler.h"
//#include "utils.h"
#include <stdint.h>
#include <assert.h>
#ifndef ELEM_SIZE
# define ELEM_SIZE 2048
#endif
struct asdf {
char c[ELEM_SIZE];
};
#if 1
void copy_data_1(void *dest, void *src) {
struct asdf *d = __builtin_assume_aligned(dest, 1);
struct asdf *s = __builtin_assume_aligned(src, 1);
*d = *s;
}
void copy_data_2(void *dest, void *src) {
struct asdf *d = __builtin_assume_aligned(dest, 2);
struct asdf *s = __builtin_assume_aligned(src, 2);
*d = *s;
}
void copy_data_4(void *dest, void *src) {
struct asdf *d = __builtin_assume_aligned(dest, 4);
struct asdf *s = __builtin_assume_aligned(src, 4);
*d = *s;
}
void copy_data_8(void *dest, void *src) {
struct asdf *d = __builtin_assume_aligned(dest, 8);
struct asdf *s = __builtin_assume_aligned(src, 8);
*d = *s;
}
void copy_data_16(void *dest, void *src) {
struct asdf *d = __builtin_assume_aligned(dest, 16);
struct asdf *s = __builtin_assume_aligned(src, 16);
*d = *s;
}
void copy_data_32(void *dest, void *src) {
struct asdf *d = __builtin_assume_aligned(dest, 16);
struct asdf *s = __builtin_assume_aligned(src, 16);
*d = *s;
}
#else
if (!((uintptr_t)dest & 15ul) && !((uintptr_t)src & 15ul))
void copy_data_1(void *dest, void *src) {
struct asdf _Alignas(1) *d = dest;
struct asdf _Alignas(1) *s = src;
*d = *s;
}
void copy_data_2(void *dest, void *src) {
struct asdf _Alignas(2) *d = dest;
struct asdf _Alignas(2) *s = src;
*d = *s;
}
void copy_data_4(void *dest, void *src) {
struct asdf _Alignas(4) *d = dest;
struct asdf _Alignas(4) *s = src;
*d = *s;
}
void copy_data_8(void *dest, void *src) {
struct asdf _Alignas(8) *d = dest;
struct asdf _Alignas(8) *s = src;
*d = *s;
}
void copy_data_16(void *dest, void *src) {
struct asdf _Alignas(16) *d = dest & ~15;
struct asdf _Alignas(16) *s = src & ~15;
*d = *s;
}
void copy_data_32(void *dest, void *src) {
struct asdf _Alignas(32) *d = dest;
struct asdf _Alignas(32) *s = src;
*d = *s;
}
#endif