Tag: gcc

128乘法和除法的内在函数

在x86_64中,我知道mul和div的代码通过将低64位放在rax中而高位放在rdx寄存器中来支持128个整数。 我在intel intrinsics指南中寻找某种内在的function,我找不到一个。 我正在写一个大字库,字大小为64位。 现在我正在用这样一个单词进行划分。 int ubi_div_i64(ubigint_t* a, ubi_i64_t b, ubi_i64_t* rem) { if(b == 0) return UBI_MATH_ERR; ubi_i64_t r = 0; for(size_t i = a->used; i– > 0;) { ubi_i64_t out; __asm__(“\t” “div %[d] \n\t” : “=a”(out), “=d”(r) : “a”(a->data[i]), “d”(r), [d]”r”(b) : “cc”); a->data[i] = out; //ubi_i128_t top = (r <data[i]; //r = […]

链接gcc没有文件的共享库?

假设我的目标系统上有一个x.so库,我的开发系统上没有x.so库。 我需要使用gcc编译我的开发机器上的程序,该程序使用该x.so在目标机器上x.so 。 有没有办法做到这一点?

正确的位移给出错误的结果,有人可以解释

我正在向-109右移-109,我期望-3,因为-109 = -1101101(二进制)右移5位-1101101 >> 5 = -11(二进制)= -3 但是,我得到-4而不是。 有人可以解释什么是错的吗? 我使用的代码: int16_t a = -109; int16_t b = a >> 5; printf(“%d %d\n”, a,b); 我在linux上使用了GCC,并在osx上使用了相同的结果。

GNU C预处理器:对宏评估的结果进行字符串化

我有一个常见的字符串宏,我想转换为长度值字符串,所有这些都在宏中,如果可能的话,所以一切都以.rodata 。 #define PAYLOAD “xyz” #define PAYLOAD_LEN (sizeof(PAYLOAD)-1) 我想将PAYLOAD_LEN用作字符串,作为另一个字符串的一部分,例如 const char lv_macro[] = “” PAYLOAD_LEN “:” PAYLOAD; const char lv_wanted[] = “3:xyz”` 我怀疑这是不可能的,我应该将PAYLOAD_LEN定义为文字,例如#define PAYLOAD_LEN 3然后进行字符串化 。 我可以,但不想,忘记.rodata并在运行时生成它,例如 char lv[64]; snprintf(lv, sizeof lv, “%zu:” PAYLOAD, PAYLOAD_LEN); 请注意,这不是已经在此处提出和回答的问题,例如,以及许多其他问题。

“警告:控制到达非void函数的结尾”但实际上该函数被声明为int并返回一个int

我有这个function: int firstHeapArray (IntHeapArray h) { if(!emptyHeapArray(h)) return h.array[0]; } 它被声明为int,这是IntHeapArray结构: typedef struct intHeapArray { int *array; int size; } IntHeapArray; 你能说出为什么我在编译时会收到这个警告吗? heap-test.c: In function ‘firstHeapArray’: heap.h:31:1: warning: control reaches end of non-void function 非常感谢你。

MSVC内联ASM到GCC

我正在尝试处理MSVC和GCC编译器,同时更新此代码库以使用GCC。 但我不确定GCC内联ASM是如何工作的。 现在我不擅长将ASM翻译成C,否则我只会使用C而不是ASM。 SLONG Div16(signed long a, signed long b) { signed long v; #ifdef __GNUC__ // GCC doesnt work. __asm() { #else // MSVC __asm { #endif mov edx, a mov ebx, b mov eax, edx shl eax, 16 sar edx, 16 idiv ebx mov v, eax } return v; } signed long ROR13(signed […]

使用OpenMP在两个核上设置线程关联

我正在使用一个C程序,使用OpenMP 4.0在Windows7上使用gcc 4.9.2编译。 我的电脑是双核,有四个线程。 我想使用线程亲和力传播并使用2个线程放在不同的核心上。 所以当我从DOS设置环境变量时: 设置OMP_NUM_THREADS = 2 设置OMP_PROC_BIND =传播 设置OMP_PLACES =“核心” 我得到了变量OMP_DISPLAY_ENV = true,这个: libgomp: Invalid value for environment variable OMP_PLACES OPENMP DISPLAY ENVIRONMENT BEGIN _OPENMP = ‘201307’ OMP_DYNAMIC = ‘FALSE’ OMP_NESTED = ‘FALSE’ OMP_NUM_THREADS = ‘2’ OMP_SCHEDULE = ‘DYNAMIC’ OMP_PROC_BIND = ‘SPREAD’ OMP_PLACES = ” OMP_STACKSIZE = ‘12872703’ OMP_WAIT_POLICY = ‘PASSIVE’ OMP_THREAD_LIMIT […]

GCC -nostdlib失败,未定义引用`__libc_csu_fini’

我为链接器提供了我的文件:ld-2.7.so,libc-2.7.so和crt1.o但是无法成功编译。 是否可以链接到默认的glibc? (静态编译或安装单独的glibc不是一种选择。) gcc -Wl,-dynamic-linker,ld-2.7.so,libc-2.7.so,crt1.o -nostdlib program.c crt1.o: In function `_start’: (.text+0x12): undefined reference to `__libc_csu_fini’ crt1.o: In function `_start’: (.text+0x19): undefined reference to `__libc_csu_init’ /tmp/user/1000/ccauFlwt.o: In function `findsize’: program.c:(.text+0x21): undefined reference to `stat’ /tmp/user/1000/ccauFlwt.o: In function `findtime’: program.c:(.text+0x4c): undefined reference to `stat’ collect2: ld returned 1 exit status

编写将函数返回给Fortran的C函数

最后,我试图编写一个IPC计算器,利用Fortran计算和C来传递两个Fortran程序之间的数据。 当我完成它将希望看起来像: Fortran program to pass input -> Client written in C -> Server written in C -> Fortran program to calculate input and pass ans back C客户端/服务器部分已完成,但目前我仍然试图编写一个在Fortran程序中输入的程序,将其传递给计算答案的C程序。 但是,我看到了一些奇怪的行为。 Fortran计划 program calculator !implicit none ! type declaration statements integer x x = 1 ! executable statements x = calc(1,1) print *, x end program calculator […]

C中对“main”的未定义引用

嗨我在使用gcc编译交流代码时遇到错误 /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../lib64/crt1.o: In function `_start’: (.text+0x20): undefined reference to `main’ collect2: ld returned 1 exit status 我试图将fftw()函数导入SystemVerilog 。 这是我的代码 #include #include #include #include #include void fftw(double FFT_in[],int size) { double *IFFT_out; int i; fftw_complex *middle; fftw_plan fft; fftw_plan ifft; middle = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*size); IFFT_out = (double *) malloc(size*sizeof(double)); fft = fftw_plan_dft_r2c_1d(size, FFT_in, middle, FFTW_ESTIMATE); //Setup […]