Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align memory start address #318

Merged
merged 7 commits into from
Mar 30, 2018
Merged

align memory start address #318

merged 7 commits into from
Mar 30, 2018

Conversation

Howave
Copy link
Contributor

@Howave Howave commented Mar 30, 2018

#pragma pack(4) is not effective for the arrays

@nihui
Copy link
Member

nihui commented Mar 30, 2018

more precisely, print platform alignment macro block into the generated memory header so that the output file could be reused on both platform.

The content in the generated code file should be like

#ifdef _MSC_VER
__declspec(align(4))
#else
__attribute__((aligned(4)))
#endif
static const unsigned char xxxxx[] = {
};

@Howave
Copy link
Contributor Author

Howave commented Mar 30, 2018

it's useless to add the macro into the generated memory header. Only if adding the macro to each array header.Test codes are as below:

@Howave
Copy link
Contributor Author

Howave commented Mar 30, 2018

#include <stdio.h>

_attribute_ ((aligned(4)))

static const unsigned char det1_param_bin[] = {
0xdd,
};

static const unsigned char det2_param_bin[] = {
0xdd,0x85,0x76,
};

static const unsigned char det3_param_bin[] = {
0xdd,0x85,
};

static const unsigned char det4_param_bin[] = {
0xdd,0x85,0x76,
};

_attribute_((packed)) static const unsigned char det5_param_bin[] = {
0xdd,0x85
};

int main(int argc, char **argv){
char *p = &det1_param_bin[0];
printf("det1_param_bin = %p\n", p);

p = &det2_param_bin[0];
printf("det2_param_bin = %p\n", p);

p = &det3_param_bin[0];
printf("det3_param_bin = %p\n", p);

p = &det4_param_bin[0];
printf("det4_param_bin = %p\n", p);

p = &det5_param_bin[0];
printf("det5_param_bin = %p\n", p);

return 0;

}

@nihui
Copy link
Member

nihui commented Mar 30, 2018

so, alignment macro should be added before both array definition.

// xyz.mem.h content

#ifdef _MSC_VER
__declspec(align(4))
#else
__attribute__((aligned(4)))
#endif
static const unsigned char xyz_param_bin[] = {
    0x07
};

#ifdef _MSC_VER
__declspec(align(4))
#else
__attribute__((aligned(4)))
#endif
static const unsigned char xyz_bin[] = {
    0x05
};

@Howave
Copy link
Contributor Author

Howave commented Mar 30, 2018

reuploaded, pls check

@nihui nihui merged commit 5e7332e into Tencent:master Mar 30, 2018
ghimiredhikura pushed a commit to ghimiredhikura/NCNNSFD that referenced this pull request Jul 26, 2020
* make memory start address 4bytes aligned
* align memory start address for MSVC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants