LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1010|回复: 10

用gcc4.0编译的究竟有什么好处?

[复制链接]
发表于 2005-5-25 11:24:02 | 显示全部楼层 |阅读模式
最近ubuntu老是有很多软件升级,是不是用gcc4.0重新编译的,我的内核2.6.10-5-686都是新的,好象也没什么太大的变化。
发表于 2005-5-25 12:41:37 | 显示全部楼层
要编译整个系统就能体现出来。。。快。。
不过gcc4.0  bug多多多
回复 支持 反对

使用道具 举报

发表于 2005-5-25 13:33:05 | 显示全部楼层
等2.6.12出来吧:)
回复 支持 反对

使用道具 举报

发表于 2005-5-25 14:35:43 | 显示全部楼层

  1. #include <stdlib.h>

  2. #define mmx_m2r(op, mem, reg) \
  3.                 __asm__ __volatile__ (#op "\t%0, %%" #reg \
  4.                                 : /* nothing */ \
  5.                                 : "X" (mem))
  6. #define movd_m2r(var, reg)      mmx_m2r(movd, var, reg)

  7. int main () {
  8.         int a;
  9.         int c;
  10.         int b;
  11.         int d;

  12.         b = 100;
  13.         c = rand () % 256;
  14.         a = 256 - c;
  15.         d = (a / 4) + 1;
  16.         movd_m2r(b, mm4);
  17.         movd_m2r(c, mm5);
  18.         movd_m2r(a, mm6);
  19.         movd_m2r(d, mm7);

  20.         return 0;
  21. }

复制代码

  1. smspc tmp # gcc -Wall -S -o - testmmx.c
  2.         .file   "testmmx.c"
  3.         .text
  4. .globl main
  5.         .type   main, @function
  6. main:
  7.         pushl   %ebp
  8.         movl    %esp, %ebp
  9.         subl    $24, %esp
  10.         andl    $-16, %esp
  11.         movl    $0, %eax
  12.         addl    $15, %eax
  13.         addl    $15, %eax
  14.         shrl    $4, %eax
  15.         sall    $4, %eax
  16.         subl    %eax, %esp
  17.         movl    $100, -8(%ebp)
  18.         call    rand
  19.         movl    %eax, %edx
  20.         movl    %edx, %eax
  21.         sarl    $31, %eax
  22.         movl    %eax, %ecx
  23.         shrl    $24, %ecx
  24.         leal    (%edx,%ecx), %eax
  25.         andl    $255, %eax
  26.         subl    %ecx, %eax
  27.         movl    %eax, -12(%ebp)
  28.         movl    $256, %eax
  29.         subl    -12(%ebp), %eax
  30.         movl    %eax, -16(%ebp)
  31.         movl    -16(%ebp), %edx
  32.         movl    %edx, %eax
  33.         sarl    $31, %eax
  34.         shrl    $30, %eax
  35.         addl    %edx, %eax
  36.         sarl    $2, %eax
  37.         incl    %eax
  38.         movl    %eax, -4(%ebp)
  39. #APP
  40.         movd    -8(%ebp), %mm4
  41.         movd    -12(%ebp), %mm5
  42.         movd    -16(%ebp), %mm6
  43.         movd    -4(%ebp), %mm7
  44. #NO_APP
  45.         movl    $0, %eax
  46.         leave
  47.         ret
  48.         .size   main, .-main
  49.         .ident  "GCC: (GNU) 4.0.0-20050522 (Gentoo 4.0.0.20050522)"
  50.         .section        .note.GNU-stack,"",@progbits

复制代码

  1. smspc tmp # gcc -Wall -S -o - testmmx.c -O
  2.         .file   "testmmx.c"
  3.         .text
  4. .globl main
  5.         .type   main, @function
  6. main:
  7.         pushl   %ebp
  8.         movl    %esp, %ebp
  9.         subl    $8, %esp
  10.         andl    $-16, %esp
  11.         subl    $16, %esp
  12.         call    rand
  13.         cltd
  14.         shrl    $24, %edx
  15.         addl    %edx, %eax
  16.         andl    $255, %eax
  17.         subl    %edx, %eax
  18.         movl    %eax, %ecx
  19.         movl    $256, %edx
  20.         subl    %eax, %edx
  21. #APP
  22.         movd    $100, %mm4
  23.         movd    %ecx, %mm5
  24.         movd    %edx, %mm6
  25. testmmx.c: In function 'main':
  26. testmmx.c:22: error: invalid 'asm': invalid expression as operand
  27.         movd    +1, %mm7
  28. #NO_APP
  29.         movl    $0, %eax
  30.         leave
  31.         ret
  32.         .size   main, .-main
  33.         .ident  "GCC: (GNU) 4.0.0-20050522 (Gentoo 4.0.0.20050522)"
  34.         .section        .note.GNU-stack,"",@progbits

复制代码

  1. Portage 2.0.51.22-r1 (default-linux/x86/2005.0, gcc-4.0.0-20050522, glibc-2.3.5.20050418-r0, 2.6.12-rc4-skunk1-unicon i686)
  2. =================================================================
  3. System uname: 2.6.12-rc4-skunk1-unicon i686 Intel(R) Celeron(R) CPU 1.70GHz
  4. Gentoo Base System version 1.6.12
  5. dev-lang/python:     2.3.5
  6. sys-apps/sandbox:    1.2.8
  7. sys-devel/autoconf:  2.13, 2.59-r6
  8. sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.5
  9. sys-devel/binutils:  2.15.97
  10. sys-devel/libtool:   1.5.16
  11. virtual/os-headers:  2.6.11
  12. ACCEPT_KEYWORDS="x86 ~x86"
  13. AUTOCLEAN="yes"
  14. CBUILD="i686-pc-linux-gnu"
  15. CFLAGS="-O1 -pipe -march=pentium4"
  16. CHOST="i686-pc-linux-gnu"
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-5-25 15:23:10 | 显示全部楼层
再来一段:

  1. smspc tmp # cat test_struct_array.c
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. typedef struct test_st {
  5.         char *name;
  6.         int  num;
  7. } test_t;

  8. static char * str[] = {
  9.         "one",
  10.         "two",
  11.         "three",
  12.         "four",
  13.         "five",
  14.         "six",
  15.         "seven"
  16. };

  17. char * get_rand_str () {
  18.         char *s = str[rand () % (sizeof(str) / sizeof(str[0]))];
  19.         return s;
  20. }

  21. int main () {
  22.         char * s [10] = {NULL};
  23.         int  i = 0;
  24.         test_t test_struct[]= {
  25.                 {
  26.                         .name = s[i] = get_rand_str(),
  27.                         .num = i++,
  28.                 },
  29.                 {
  30.                         .name = s[i] = get_rand_str(),
  31.                         .num = i++,
  32.                 },
  33.                 {
  34.                         .name = s[i] = get_rand_str(),
  35.                         .num = i++,
  36.                 },
  37.                 {
  38.                         .name = s[i] = get_rand_str(),
  39.                         .num = i++,
  40.                 },
  41.                 {
  42.                         .name = s[i] = get_rand_str(),
  43.                         .num = i++,
  44.                 },
  45.         };
  46.         test_t * tp;
  47.         int j;
  48.         tp = test_struct;

  49.         printf ("i = %d\n", i);
  50.         for (j = 0; j < sizeof (test_struct) / sizeof(test_struct[0]); j ++) {
  51.                 printf ("name `%s\' num \'%d\' s[%d] = `%s\'\n", tp->name, tp->num, j, s[j]);
  52.                 tp ++;
  53.         }

  54.         return 0;
  55. }

复制代码

  1. smspc tmp # LANG=C LC_ALL=C gcc -Wall  test_struct_array.c  -g
  2. smspc tmp # ./a.out
  3. i = 5
  4. name `two' num '0' s[0] = `two'
  5. name `five' num '0' s[1] = `(null)'
  6. name `three' num '0' s[2] = `(null)'
  7. name `six' num '0' s[3] = `(null)'
  8. name `two' num '0' s[4] = `(null)'

复制代码

  1. smspc tmp # gcc-config 1
  2. * Switching to i686-pc-linux-gnu-3.4.3-20050110 compiler ...             [ ok ]
  3. * If you intend to use the gcc from the new profile in an already
  4. * running shell, please remember to do:

  5. *   # source /etc/profile

  6. smspc tmp # source /etc/profile
  7. smspc tmp # LANG=C LC_ALL=C gcc -Wall  test_struct_array.c  -g
  8. smspc tmp # ./a.out
  9. i = 5
  10. name `two' num '0' s[0] = `two'
  11. name `five' num '1' s[1] = `five'
  12. name `three' num '2' s[2] = `three'
  13. name `six' num '3' s[3] = `six'
  14. name `two' num '4' s[4] = `two'

复制代码
回复 支持 反对

使用道具 举报

发表于 2005-5-25 15:35:51 | 显示全部楼层
所以现在还是不要用  gcc4 的好
回复 支持 反对

使用道具 举报

发表于 2005-5-25 17:17:34 | 显示全部楼层
breezy 的很多软件都换成 GCC 4.0 了
回复 支持 反对

使用道具 举报

发表于 2005-5-26 15:52:59 | 显示全部楼层
大势所趋,哈哈
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-26 16:34:06 | 显示全部楼层
现在hoary可以升级到breezy了吗?
回复 支持 反对

使用道具 举报

发表于 2005-5-26 16:40:53 | 显示全部楼层
现在还是问题多多,还是别升了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表