memory-alignment

Combining __restrict__ and __attribute__((aligned(32)))

允我心安 提交于 2020-03-26 04:29:25
问题 I want to ensure that gcc knows: The pointers refer to non-overlapping chunks of memory The pointers have 32 byte alignments Is the following the correct? template<typename T, typename T2> void f(const T* __restrict__ __attribute__((aligned(32))) x, T2* __restrict__ __attribute__((aligned(32))) out) {} Thanks. Update: I try to use one read and lots of write to saturate the cpu ports for writing. I hope that would make the performance gain by aligned moves more significant. But the assembly

Linaro g++ aarch64 compilation cause unalignment fault

白昼怎懂夜的黑 提交于 2020-03-04 05:20:34
问题 I'm using linaro g++ for ARM arch64 to compile a simple cpp file: int main() { char *helloMain = "main module (crm.c)"; long faculty, num = 12; int stop,mainLoop = 1; char word[80] = ""; } After objdump the generated elf file, I got its asm code: 0000000000001270 <main>: int main() { 1270: d101c3ff sub sp, sp, #0x70 char *helloMain = "main module (crm.c)"; 1274: 90000020 adrp x0, 5000 <_malloc_trim_r+0x160> 1278: 9111c000 add x0, x0, #0x470 127c: f90003e0 str x0, [sp] long faculty, num = 12;

how does the processor read memory?

江枫思渺然 提交于 2020-02-15 18:06:24
问题 I'm trying to re-implement malloc and I need to understand the purpose of the alignment. As I understand it, if the memory is aligned, the code will be executed faster because the processor won't have to take an extra step to recover the bits of memory that are cut. I think I understand that a 64-bit processor reads 64-bit by 64-bit memory. Now, let's imagine that I have a structure with in order (without padding): a char, a short, a char, and an int. Why will the short be misaligned? We have

how does the processor read memory?

不羁的心 提交于 2020-02-15 18:05:40
问题 I'm trying to re-implement malloc and I need to understand the purpose of the alignment. As I understand it, if the memory is aligned, the code will be executed faster because the processor won't have to take an extra step to recover the bits of memory that are cut. I think I understand that a 64-bit processor reads 64-bit by 64-bit memory. Now, let's imagine that I have a structure with in order (without padding): a char, a short, a char, and an int. Why will the short be misaligned? We have

C Function alignment in GCC

丶灬走出姿态 提交于 2020-02-01 03:24:04
问题 I am trying to byte-align a function to 16-byte boundary using the 'aligned(16)' attribute. I did the following: void __attribute__((aligned(16))) function() { } (Source: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) But when I compile (gcc foo.c ; no makefiles or linker scripts used), I get the following error: FOO.c:99: error: alignment may not be specified for 'function' I tried aligning to 4,8,32, etc as well but the error remains the same. I need this to align an Interrupt

Custom data size for memory alignment

ⅰ亾dé卋堺 提交于 2020-01-17 12:39:09
问题 Each datatype has a certain range, based on the hardware. For example, on a 32bit machine an int has the range -2147483648 to 2147483647. C++ compilers 'pad' object memory to fit into certain sizes. I'm pretty sure it's 2, 4, 8, 16, 32, 64 etc. This also probably depends on the machine. I want to manually align my objects to meet padding requirements. Is there a way to: Determine what machine a program is running on Determine padding sizes Set custom data-type based on bitsize I've used

pointer returned by shmat points at the end of address space which gives seg fault

纵然是瞬间 提交于 2020-01-16 03:30:12
问题 //TeamSize is an integer int Seg_id = shmget(SHM_KEY,sizeof(Word)*TeamSize,IPC_CREAT); void* Seg_ptr = shmat(Seg_id,0,0); new(Seg_ptr) Word[TeamSize]; I am having trouble with this segment of code. The Word class is a class that I defined with 8 bytes char array and some parse functions. I think I am using shmget and shmat just like how others use them. But I keep getting seg fault. When I print out Seg_id, it looks normal just some number. But Seg_ptr points at 0xffffffffffffffff. Then the

Variant type storage and alignment issues

让人想犯罪 __ 提交于 2020-01-07 07:46:29
问题 I've made a variant type to use instead of boost::variant. Mine works storing an index of the current type on a list of the possible types, and storing data in a byte array with enough space to store the biggest type. unsigned char data[my_types::max_size]; int type; Now, when I write a value to this variant type comes the trouble. I use the following: template<typename T> void set(T a) { int t = type_index(T); if (t != -1) { type = t; puts("writing atom data"); *((T *) data) = a; //THIS PART

C Avoiding Alignment Issues

谁说胖子不能爱 提交于 2020-01-06 07:45:03
问题 Could some please explain, what is really wrong with the following example, especially the part with "which might result in the 32-bit unsigned long being loaded from an address that is not a multiple of four": "The compiler generally prevents alignment issues by naturally aligning all data types. In fact, alignment issues are normally not major concerns of the kernel developersthe gcc folks have to worry about them. Issues arise, however, when the programmer plays too closely with pointers

C Avoiding Alignment Issues

為{幸葍}努か 提交于 2020-01-06 07:44:26
问题 Could some please explain, what is really wrong with the following example, especially the part with "which might result in the 32-bit unsigned long being loaded from an address that is not a multiple of four": "The compiler generally prevents alignment issues by naturally aligning all data types. In fact, alignment issues are normally not major concerns of the kernel developersthe gcc folks have to worry about them. Issues arise, however, when the programmer plays too closely with pointers