×ðÁú¿­Ê±

LinuxÏÂʹÓÃGCC¾ÙÐÐǶÈëʽARM»ã±àÓÅ»¯µÄ³£¼ûÉèÖü¼ÇÉ

linuxÏÂʹÓÃgcc¾ÙÐÐǶÈëʽarm»ã±àÓÅ»¯µÄ³£¼ûÉèÖü¼ÇÉ

ͻ񻣼

Ëæ×ÅǶÈëʽϵͳµÄÆÕ¼°ºÍÉú³¤£¬¶ÔÐÔÄܵÄÒªÇóÈÕÒæÌá¸ß£¬Ç¶ÈëʽARM»ã±àÓÅ»¯³ÉΪºÜÊÇÖ÷ÒªµÄ»·½Ú¡£±¾ÎĽ«ÏÈÈÝÔÚLinuxÏÂʹÓÃGCC¾ÙÐÐARM»ã±àÓÅ»¯µÄ³£¼ûÉèÖü¼ÇÉ£¬²¢ÍŽá´úÂëʾÀý¾ÙÐÐÏêϸ˵Ã÷¡£ÕâЩÉèÖü¼ÇÉ°üÀ¨±àÒëÑ¡Ïî¡¢ÄÚÁª»ã±à¡¢¼Ä´æÆ÷Ñ¡ÔñºÍÑ­»·ÓÅ»¯µÈ·½Ã棬¿ÉÒÔ×ÊÖú¿ª·¢Õß³ä·ÖÑéÕ¹ARM¼Ü¹¹µÄÐÔÄÜÓÅÊÆ¡£

±àÒëÑ¡Ïî

GCC±àÒëÆ÷ÌṩÁËһЩѡÏîÓÃÓÚÓÅ»¯ARM»ã±à´úÂë¡£³£ÓõÄÑ¡ÏîÓÐ-O£¨ÓÅ»¯¼¶±ð£©¡¢-march£¨Ä¿µÄ¼Ü¹¹£©¡¢-mtune£¨Ä¿µÄ´¦Öóͷ£Æ÷ÀàÐÍ£©µÈ¡£

ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÐÐÉèÖñàÒëÑ¡Ï

gcc -O3 -march=armv7-a -mtune=cortex-a9 -c mycode.c -o mycode.o

µÇ¼ºó¸´ÖÆ

ÕâÀïµÄ-O3ÌåÏÖ×î¸ß¼¶±ðµÄÓÅ»¯£¬-march=armv7-aÖ¸¶¨Ä¿µÄ¼Ü¹¹ÎªARMv7-A£¬-mtune=cortex-a9Ö¸¶¨Ä¿µÄ´¦Öóͷ£Æ÷ÀàÐÍΪCortex-A9¡£Í¨¹ýºÏÀíÉèÖñàÒëÑ¡Ï¿ÉÒÔʹµÃÌìÉúµÄ»ã±à´úÂëÔ½·¢¸ßЧ¡£

ÄÚÁª»ã±à

GCCÌṩÁËÄÚÁª»ã±àµÄ¹¦Ð§£¬¿ÉÒÔÔÚC´úÂëÖÐÖ±½ÓǶÈë»ã±à´úÂë¡£ÄÚÁª»ã±àʹµÃÎÒÃÇ¿ÉÒÔ³ä·ÖÑéÕ¹»ã±àÓïÑÔµÄÓÅÊÆ£¬²¢ÇÒ¿ÉÒÔʵÏÖ¸ü¸ßµÄÐÔÄÜ¡£

ʾÀý´úÂëÈçÏ£º

int add(int a, int b)
{
    int result;
    asm volatile(
        "add %[result], %[a], %[b]"
        : [result] "=r"(result)
        : [a] "r"(a), [b] "r"(b)
    );
    return result;
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇͨ¹ýÄÚÁª»ã±àʵÏÖÁËÁ½¸öÕûÊýÏà¼ÓµÄ¹¦Ð§¡£Í¨¹ýʹÓÃ%[result]¡¢%[a]ºÍ%[b]±äÁ¿Ìæ»»¶ÔÓ¦µÄ¼Ä´æÆ÷£¬¿ÉÒÔÔÚǶÈëʽARM»ã±àÖÐÒýÓÃC´úÂëÖеıäÁ¿¡£Í¨¹ýÕâÖÖ·½·¨£¬ÎÒÃÇ¿ÉÒÔ³ä·ÖʹÓûã±àÓïÑÔµÄÎÞаÐÔ£¬ÊµÏÖ¸ü¸ßЧµÄ´úÂë¡£

¼Ä´æÆ÷Ñ¡Ôñ

ÔÚ±àдǶÈëʽARM»ã±à´úÂëʱ£¬Ñ¡ÔñºÏÊʵļĴæÆ÷¹ØÓÚÐÔÄÜÓÅ»¯ºÜÊÇÖ÷Òª¡£Ò»·½Ã棬Ҫ³ä·ÖʹÓÃARM¼Ü¹¹ÌṩµÄ¶à¸ö¼Ä´æÆ÷£¬×èֹƵÈÔµÄÊý¾Ý¼ÓÔغʹ洢²Ù×÷¡£ÁíÒ»·½Ã棬Ҫ×èÖ¹¼Ä´æÆ÷Òç³öºÍ³åÍ»£¬È·±£»ã±à´úÂëÔËÐеÄ׼ȷÐÔ¡£

ʾÀý´úÂëÈçÏ£º

int multiply(int a, int b)
{
    int result;
    asm volatile(
        "mov r0, %[a]
"
        "mov r1, %[b]
"
        "mul %[result], r0, r1"
        : [result] "=r"(result)
        : [a] "r"(a), [b] "r"(b)
        : "r0", "r1"
    );
    return result;
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇʹÓüĴæÆ÷r0ºÍr1»®·Ö´æ´¢ÊäÈë²ÎÊýaºÍb£¬È»ºóʹÓÃmulÖ¸Áî¾ÙÐг˷¨ÔËË㣬²¢½«Ð§¹ûÉúÑĵ½result±äÁ¿ÖС£Í¨¹ýºÏÀíÑ¡Ôñ¼Ä´æÆ÷£¬¿ÉÒÔ×èÖ¹¼Ä´æÆ÷Òç³öºÍ³åÍ»µÄÎÊÌ⣬²¢Ìá¸ß´úÂëµÄЧÂÊ¡£

Ñ­»·ÓÅ»¯

ÔÚǶÈëʽϵͳÖУ¬Ñ­»·ÊǾ­³£Óõ½µÄ¿ØÖƽṹ¡£ÓÅ»¯Ñ­»·´úÂë¿ÉÒÔÏÔ×ÅÌá¸ß³ÌÐòµÄÐÔÄÜ¡£GCC±àÒëÆ÷ÌṩÁËһЩÓÅ»¯Ñ¡ÏÓÃÓÚÓÅ»¯Ñ­»·´úÂë¡£

ʾÀý´úÂëÈçÏ£º

void sum(int *data, int size)
{
    int sum = 0;
    for (int i = 0; i < size; i++)
    {
        sum += data[i];
    }
    asm volatile(
        "mov %[sum], r0"
        : [sum] "=r"(sum)
        :
        : "r0"
    );
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇͨ¹ýÓÅ»¯Ñ­»·´úÂ룬½«ÀÛ¼Ó²Ù×÷·ÅÈëÁË»ã±à²¿·Ö¡£Í¨¹ýÕâÖÖ·½·¨£¬¿ÉÒÔïÔÌ­Ñ­»·¿¢ÊÂÌõ¼þµÄÅжÏ£¬Ìá¸ßÑ­»·µÄÖ´ÐÐЧÂÊ¡£Í¬Ê±£¬ÎÒÃÇʹÓüĴæÆ÷r0´æ´¢ÀÛ¼ÓЧ¹û£¬Í¨¹ýºÏÀíÑ¡Ôñ¼Ä´æÆ÷£¬×èÖ¹¼Ä´æÆ÷Òç³öºÍ³åÍ»µÄÎÊÌâ¡£

½áÂÛ£º

±¾ÎÄÏÈÈÝÁËÔÚlinuxÏÂʹÓÃgcc¾ÙÐÐǶÈëʽarm»ã±àÓÅ»¯µÄ³£¼ûÉèÖü¼ÇÉ£¬²¢ÍŽá´úÂëʾÀý¾ÙÐÐÁËÏêϸ˵Ã÷¡£ÕâЩÉèÖü¼ÇÉ°üÀ¨±àÒëÑ¡Ïî¡¢ÄÚÁª»ã±à¡¢¼Ä´æÆ÷Ñ¡ÔñºÍÑ­»·ÓÅ»¯µÈ·½Ã棬¿ÉÒÔ×ÊÖú¿ª·¢Õß³ä·ÖÑéÕ¹ARM¼Ü¹¹µÄÐÔÄÜÓÅÊÆ£¬Ìá¸ßǶÈëʽϵͳµÄÐÔÄܺÍЧÂÊ¡£

ÒÔÉϾÍÊÇLinuxÏÂʹÓÃGCC¾ÙÐÐǶÈëʽARM»ã±àÓÅ»¯µÄ³£¼ûÉèÖü¼ÇɵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿