/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/pagecpy.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-11-20 04:55:36 UTC
  • Revision ID: csa@suren.me-20151120045536-5sx82ghdzaimuu8w
Fix AVX memory copy

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
88
88
*/
89
89
 
90
 
void pcilib_memcpy4k_avx(void *dst, void *src, size_t size) {
 
90
void pcilib_memcpy4k_avx(void *dst, const void *src, size_t size) {
91
91
    size_t sse_size = (size / 512);
92
92
 
93
93
    __asm__ __volatile__ (
96
96
 
97
97
            "1:                                 \n\t"
98
98
 
99
 
            "vmovdqa       (%0,%%rax), %%ymm0   \n\t"
100
 
            "vmovdqa     32(%0,%%rax), %%ymm1   \n\t"
101
 
            "vmovdqa     64(%0,%%rax), %%ymm2   \n\t"
102
 
            "vmovdqa     96(%0,%%rax), %%ymm3   \n\t"
103
 
            "vmovdqa    128(%0,%%rax), %%ymm4   \n\t"
104
 
            "vmovdqa    160(%0,%%rax), %%ymm5   \n\t"
105
 
            "vmovdqa    192(%0,%%rax), %%ymm6   \n\t"
106
 
            "vmovdqa    224(%0,%%rax), %%ymm7   \n\t"
107
 
 
108
 
            "vmovdqa    256(%0,%%rax), %%ymm8   \n\t"
109
 
            "vmovdqa    288(%0,%%rax), %%ymm9   \n\t"
110
 
            "vmovdqa    320(%0,%%rax), %%ymm10  \n\t"
111
 
            "vmovdqa    352(%0,%%rax), %%ymm11  \n\t"
112
 
            "vmovdqa    384(%0,%%rax), %%ymm12  \n\t"
113
 
            "vmovdqa    416(%0,%%rax), %%ymm13  \n\t"
114
 
            "vmovdqa    448(%0,%%rax), %%ymm14  \n\t"
115
 
            "vmovdqa    480(%0,%%rax), %%ymm15  \n\t"
116
 
 
117
 
            "vmovntps   %%ymm0,    (%1,%%rax)   \n\t"
118
 
            "vmovntps   %%ymm1,  32(%1,%%rax)   \n\t"
119
 
            "vmovntps   %%ymm2,  64(%1,%%rax)   \n\t"
120
 
            "vmovntps   %%ymm3,  96(%1,%%rax)   \n\t"
121
 
            "vmovntps   %%ymm4, 128(%1,%%rax)   \n\t"
122
 
            "vmovntps   %%ymm5, 160(%1,%%rax)   \n\t"
123
 
            "vmovntps   %%ymm6, 192(%1,%%rax)   \n\t"
124
 
            "vmovntps   %%ymm7, 224(%1,%%rax)   \n\t"
125
 
 
126
 
            "vmovntps   %%ymm8,  256(%1,%%rax)  \n\t"
127
 
            "vmovntps   %%ymm9,  288(%1,%%rax)  \n\t"
128
 
            "vmovntps   %%ymm10, 320(%1,%%rax)  \n\t"
129
 
            "vmovntps   %%ymm11, 352(%1,%%rax)  \n\t"
130
 
            "vmovntps   %%ymm12, 384(%1,%%rax)  \n\t"
131
 
            "vmovntps   %%ymm13, 416(%1,%%rax)  \n\t"
132
 
            "vmovntps   %%ymm14, 448(%1,%%rax)  \n\t"
133
 
            "vmovntps   %%ymm15, 480(%1,%%rax)  \n\t"
 
99
            "vmovdqa       (%1,%%rax), %%ymm0   \n\t"
 
100
            "vmovdqa     32(%1,%%rax), %%ymm1   \n\t"
 
101
            "vmovdqa     64(%1,%%rax), %%ymm2   \n\t"
 
102
            "vmovdqa     96(%1,%%rax), %%ymm3   \n\t"
 
103
            "vmovdqa    128(%1,%%rax), %%ymm4   \n\t"
 
104
            "vmovdqa    160(%1,%%rax), %%ymm5   \n\t"
 
105
            "vmovdqa    192(%1,%%rax), %%ymm6   \n\t"
 
106
            "vmovdqa    224(%1,%%rax), %%ymm7   \n\t"
 
107
 
 
108
            "vmovdqa    256(%1,%%rax), %%ymm8   \n\t"
 
109
            "vmovdqa    288(%1,%%rax), %%ymm9   \n\t"
 
110
            "vmovdqa    320(%1,%%rax), %%ymm10  \n\t"
 
111
            "vmovdqa    352(%1,%%rax), %%ymm11  \n\t"
 
112
            "vmovdqa    384(%1,%%rax), %%ymm12  \n\t"
 
113
            "vmovdqa    416(%1,%%rax), %%ymm13  \n\t"
 
114
            "vmovdqa    448(%1,%%rax), %%ymm14  \n\t"
 
115
            "vmovdqa    480(%1,%%rax), %%ymm15  \n\t"
 
116
 
 
117
            "vmovdqa    %%ymm0,    (%0,%%rax)   \n\t"
 
118
            "vmovdqa    %%ymm1,  32(%0,%%rax)   \n\t"
 
119
            "vmovntps   %%ymm2,  64(%0,%%rax)   \n\t"
 
120
            "vmovntps   %%ymm3,  96(%0,%%rax)   \n\t"
 
121
            "vmovntps   %%ymm4, 128(%0,%%rax)   \n\t"
 
122
            "vmovntps   %%ymm5, 160(%0,%%rax)   \n\t"
 
123
            "vmovntps   %%ymm6, 192(%0,%%rax)   \n\t"
 
124
            "vmovntps   %%ymm7, 224(%0,%%rax)   \n\t"
 
125
 
 
126
            "vmovntps   %%ymm8,  256(%0,%%rax)  \n\t"
 
127
            "vmovntps   %%ymm9,  288(%0,%%rax)  \n\t"
 
128
            "vmovntps   %%ymm10, 320(%0,%%rax)  \n\t"
 
129
            "vmovntps   %%ymm11, 352(%0,%%rax)  \n\t"
 
130
            "vmovntps   %%ymm12, 384(%0,%%rax)  \n\t"
 
131
            "vmovntps   %%ymm13, 416(%0,%%rax)  \n\t"
 
132
            "vmovntps   %%ymm14, 448(%0,%%rax)  \n\t"
 
133
            "vmovntps   %%ymm15, 480(%0,%%rax)  \n\t"
134
134
 
135
135
            "add        $512, %%rax             \n\t"
136
136
            "dec        %2                      \n\t"
137
137
            "jnz        1b                      \n\t"
138
138
            "pop        %2                      \n\t"
139
139
 
140
 
            "sfence"
 
140
            "mfence"
141
141
    :
142
142
    : "p" (dst), "p" (src), "r" (sse_size)
143
143
    : "%rax"
144
144
        );
145
145
}
146
146
 
147
 
void pcilib_pagecpy(void *dst, void *src, size_t size) {
 
147
void pcilib_pagecpy(void *dst, const void *src, size_t size) {
148
148
    int gen = pcilib_get_cpu_gen();
149
 
    if ((gen > 3)&&(size%4096==0)&&((uintptr_t)dst%32==0)&&((uintptr_t)src%32==0)) {
 
149
    if ((gen > 3)&&((size%4096)==0)&&(((uintptr_t)dst%32)==0)&&(((uintptr_t)src%32)==0)) {
150
150
        pcilib_memcpy4k_avx(dst, src, size);
151
151
    } else
152
152
        memcpy(dst, src, size);