DSP汇编中的循环问题

2019-03-26 16:36发布

  我的板子是c6740,编写测试程序想把两个数组对应的数相乘存到第三个数组中,主文件是:
#include <stdio.h> int MPY_1(int *m, int *n, int *result, int count); void main()
{
 int n[10] = {1,2,3,4,5,6,7,8,9,10};
 int m[10] = {11,12,13,14,15,16,17,18,19,20};
 int tmp,i;
 int *result;
 result = (int *)malloc(10*sizeof(int));
 tmp = MPY_1(m,n,result,10);
 for(i=0;i<10;i++)
  printf("m=%d,n=%d,result=%d,d=%d ",m,n,result,tmp); }
/**************调用汇编函数文件****************/
 .text
 .global _MPY_1
_MPY_1:     .asg A4, p_m
  .asg B4, p_n
  .asg A6, p_result
  .asg B6, B_count
  .asg A1, A_m
  .asg B1, B_n
  .asg A3, A_loopcount
  .asg A7, A_s
* ================= LOOP PROLOG ============================ *
   MV .S1 B6, A_loopcount    || MV .L1 A4,B4   || MV .L2 A5,B5
 SUB .S1 A_loopcount, 1,A_loopcount
* ===================== LOOP KERNEL ============================== *
loop:
    LDW .D1 *A5++[1], A_m ;A_m = *m
  ||  LDW .D2 *B5++[1], B_n ;A_n = *n
   MPY .M1 A_m,B_n,A_s ; A_S = m * n 
    NOP 1
 STW .D1 A_s,*A6++[1]  ; result = A_S
  
 ||[A_loopcount] B .S2 loop    ; branch ,Illegal register for conditional
    ||[A_loopcount]SUB .S1 A_loopcount, 1,A_loopcount
 
* ===================== LOOP EPILOG ============================== *
 B .S2 B3   ;return
 MVK .S1 1,A4 ;return 1
 nop 1
 .end   这程序编译没通过,在||[A_loopcount] B .S2 loop   这条语句下报错Illegal register for conditional。
第一次写汇编循环,请大侠帮看下这个程序哪些地方出错了?需要怎么改才能实现所想要的功能,谢谢! [ 本帖最后由 breeze505 于 2012-4-27 14:35 编辑 ] 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
18条回答
breeze505
2019-03-27 04:09
< 非常感谢,经过你的指导,我添加了4个NOP来等待跳转,代码OK了,但感觉这样程序中NOP很多,效率不高,我的代码如下:
.text
        .global _MPY_1
_MPY_1:
                .asg A6, p_result
                .asg B6, B_count
                .asg A7, A_m
                .asg B7, B_n
                .asg A1, A_loopcount
                .asg A8, A_s
* ================= LOOP PROLOG ============================ *
          MV .S1 B6, A_loopcount       
* ===================== LOOP KERNEL ============================== *
loop:
           LDW .D1T1 *A4++[1], A_m ;A_m = *m
        ||LDW .D2T2 *B4++[1], B_n ;A_n = *n
    NOP 5
          MPY .M1X A_m,B_n,A_s ; A_S = m * n       
           NOP 1
   SUB .S1 A_loopcount, 1,A_loopcount       
  ||STW .D1 A_s,*p_result++[1]  ; result = A_S               
  ||[A_loopcount] B .S2 loop
  NOP 5
       
* ===================== LOOP EPILOG ============================== *
        B .S2 B3   ;return
        MVK .S1 1,A4 ;return 1
        nop 1
        .end

现在C接口做如下改变:
typedef unsigned char BYTE;
int MPY_1( BYTE*m, BYTE*n, BYTE*result, int count);
我的目的是:因为乘法器16*16是最快的,那我们是否可以把传入的BYTE数组一次读取两个元素,这样循环只需要进行5次就够了,但不知道怎么一次操作两个元素。可以帮忙指导下吗?就如上面那个代码里需要做上面修改呢?

一周热门 更多>