내 코드가 신호의 엔트로피를 찾으려고합니다 ('데이터'및 '프레임 간'에 저장 됨 - 전체 코드에서 신호를 포함 할 것입니다. 임의의 값에서). 'gcc temp.c'로 컴파일하면 컴파일되고 정상적으로 실행됩니다. 출력 :이 플래그로 컴파일 할 때 코드가 실행되지 않습니다.
entropy: 40.174477
features: 0022FD06
features[0]: 40
entropy: 40
하지만 컴파일 할 때 'gcc가 -mstackrealign -msse -Os -ftree - 벡터화의 temp.c은'다음은 컴파일하지만 라인 그것은 모든 4 개 개의 플래그를 가질 필요가 48 이상으로 실행되지 실패하기 위해서 - 그들 중 세 명은 잘 실행됩니다.
코드가 이상하게 보입니다. 훨씬 더 큰 프로그램에서 실패한 비트 만 잘라 냈습니다. 필자는 컴파일러 플래그가하는 일에 관해서 가장 안 좋은 생각을 가지고 있습니다. 다른 누군가는 그것들을 넣었습니다. (보통 더 많은 것들이 있지만, 나쁜 것들이었습니다).
모두 감사합니다.
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include <math.h>
static void calc_entropy(volatile int16_t *features, const int16_t* data,
const int16_t* interframe, int frame_length);
int main()
{
int frame_length = 128;
int16_t data[128] = {1, 2, 3, 4};
int16_t interframe[128] = {1, 1, 1};
int16_t a = 0;
int16_t* features = &a;
calc_entropy(features, data, interframe, frame_length);
features += 1;
fprintf(stderr, "\nentropy: %d", a);
return 0;
}
static void calc_entropy(volatile int16_t *features, const int16_t* data,
const int16_t* interframe, int frame_length)
{
float histo[65536] = {0};
float* histo_zero = histo + 32768;
volatile float entropy = 0.0f;
int i;
for(i=0; i<frame_length; i++){
histo_zero[data[i]]++;
histo_zero[interframe[i]]++;
}
for(i=-32768; i < 32768; i++){
if(histo_zero[i])
entropy -= histo_zero[i]*logf(histo_zero[i]/(float)(frame_length*2));
}
fprintf(stderr, "\nentropy: %f", entropy);
fprintf(stderr, "\nfeatures: %p", features);
features[0] = entropy; //execution fails here
fprintf(stderr, "\nfeatures[0]: %d", features[0]);
}
편집 : 저는 gcc 4.5.2와 x86 아키텍처를 사용하고 있습니다. 또한 컴파일하고 우분투 (gcc -lm -mstackrealign -msse -Os -ftree-vectorize temp.c)를 실행하는 VirtualBox에서 실행하면 올바르게 실행됩니다.
Edit2가 : 나는 프로그램이 실행 중지되었음을 말해 창에서 다음
entropy: 40.174477
features: 00000000
과 메시지가 표시됩니다.
Edit3 : 내가 원래 gcc 4.7.0으로 업데이트 한 질문을 게시 한 이후 5 개월 만에 코드가 제대로 실행됩니다. gcc 4.5.2로 돌아가 실패했습니다. 아직도 이유를 모른다!
48 번 줄까지 계산합니까? 실패한 곳에 코멘트를 추가하십시오. – Joe
나는 당신의 코드를 최소화하려고 할 것이지만 그것은 나를 위해 일한다. gcc 4.5.2, x86. 어떻게 실패하고있는 거지? – Hasturkun