History

Increase alignment of av_malloc() as needed by AVX ASM.

Vitor Sessak committed 15 years ago

Commit 13dfce31 parent 33cbfa61 file · +7 −9Browse files

Unified · Split

libavutil/mem.c+7−9
@@ -69,21 +69,21 @@ void *av_malloc(size_t size) · 68 unmodified lines
69#endif69#endif
70 70
71 /* let's disallow possible ambiguous cases */71 /* let's disallow possible ambiguous cases */
72 if(size > (INT_MAX-16) )72 if(size > (INT_MAX-32) )
73 return NULL;73 return NULL;
74 74
75#if CONFIG_MEMALIGN_HACK75#if CONFIG_MEMALIGN_HACK
76 ptr = malloc(size+16);76 ptr = malloc(size+32);
77 if(!ptr)77 if(!ptr)
78 return ptr;78 return ptr;
79 diff= ((-(long)ptr - 1)&15) + 1;79 diff= ((-(long)ptr - 1)&31) + 1;
80 ptr = (char*)ptr + diff;80 ptr = (char*)ptr + diff;
81 ((char*)ptr)[-1]= diff;81 ((char*)ptr)[-1]= diff;
82#elif HAVE_POSIX_MEMALIGN82#elif HAVE_POSIX_MEMALIGN
83 if (posix_memalign(&ptr,16,size))83 if (posix_memalign(&ptr,32,size))
84 ptr = NULL;84 ptr = NULL;
85#elif HAVE_MEMALIGN85#elif HAVE_MEMALIGN
86 ptr = memalign(16,size);86 ptr = memalign(32,size);
87 /* Why 64?87 /* Why 64?
88 Indeed, we should align it:88 Indeed, we should align it:
89 on 4 for 38689 on 4 for 386
@@ -93,10 +93,8 @@ void *av_malloc(size_t size) · 3 unmodified lines
93 Because L1 and L2 caches are aligned on those values.93 Because L1 and L2 caches are aligned on those values.
94 But I don't want to code such logic here!94 But I don't want to code such logic here!
95 */95 */
96 /* Why 16?96 /* Why 32?
97 Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs97 For AVX ASM. SSE / NEON needs only 16.
98 it will just trigger an exception and the unaligned load will be done in the
99 exception handler or it will just segfault (SSE2 on P4).
100 Why not larger? Because I did not see a difference in benchmarks ...98 Why not larger? Because I did not see a difference in benchmarks ...
101 */99 */
102 /* benchmarks with P3100 /* benchmarks with P3

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t