×ðÁú¿­Ê±¹ÙÍøµÇ¼

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
ÍøÕ¾µØͼ