2016-06-15 150 views
0

指令數我有其上SPARC T1 RTL代碼運行(經由TEH彙編其轉換爲存儲圖像)的SPARC彙編文件。但是我需要知道RTL正在執行多少條指令。無法在文件中手動計算指令的數量。我非常感激,如果你能告訴我一個辦法做到這一點...計算在彙編語言文件

由於文件大,我附上了Dropbox的鏈接: https://dl.dropboxusercontent.com/u/48635184/exu_muldiv.s

但這裏是代碼的前幾行:

/*********************************************************************** 
* Name: exu_muldiv.s 
* Date: April 23, 2003 
* 
* Description: Execute Mulx, Mulscc, Smul, Smulcc, Umul, Umulcc, 
* Sdiv, Sdivcc, Sdivx, Udiv, Udivcc, Udivx with interesting data 
* patterns in multiple threads. Also play with delay slots and 
* intermixed mul and div operations. 
* 
* This test depends on SAS for result checking.  
* 
**********************************************************************/ 

! be sure to update when adding cases... 
#define NUM_MUL_CASES 6 
#define NUM_DIV_CASES 4 
#define NUM_IMMED_CASES 5  

! for divide by zero cases 
#define H_T0_Division_By_Zero 
#define My_T0_Division_By_Zero \ 
rdpr %tstate, %i1; \ 
rdpr %tt, %i1; \ 
rdpr %tpc, %i0; \ 
rdpr %tnpc, %i1; \ 
done; \ 
nop;  

/*******************************************************/  
#include "boot.s" 

.global main 
main: 
th_fork(th_main,%l0)  ! start up to four threads. 
    ! All threads do the same thing, but with different data patterns. 
    ! No need to run more than one core. 
th_main_0: 
    setx mul_data_t0,%g7,%g1 
     ba all_threads1 
    nop 

th_main_1: 
     setx mul_data_t1,%g7,%g1 
    ba all_threads1 
    nop 

th_main_2: 
    setx mul_data_t2,%g7,%g1 
     ba all_threads1 
    nop 

th_main_3: 
    setx mul_data_t3,%g7,%g1 
    ba all_threads1 
    nop 

all_threads1:  
    !************************************************************* 
    ! Operand2 as a register: MULX, UMUL, SMUL, UMULcc, SMULcc 
    !************************************************************* 
    add %g0,NUM_MUL_CASES,%g2 
    mova %icc,%g1,%g3  ! keep the multiply operand address handy 

mul_loop1: 
    ldx [%g1],%l1 
    ldx [%g1+8],%l2 
    wr %g0,%g0,%ccr  ! ccr clear 

    mulx %l1,%l2,%l4 
    umul %l1,%l2,%l5 
    rd %y,%i1   ! be sure SAS looks at Y-reg 
    smul %l1,%l2,%l6 
    rd %y,%i1 

     wr %g0,%g0,%ccr  ! clear ccr  
    umulcc %l1,%l2,%l7  
    rd %y,%i1 
     wr %g0,%g0,%ccr   
    smulcc %l1,%l2,%l6  
    rd %y,%i1 

     wr %g0,0xff,%ccr  ! set ccr. Should not matter.  
    umulcc %l1,%l2,%l7  
    rd %y,%i1 
     wr %g0,0xff,%ccr  
    smulcc %l1,%l2,%l6  
    rd %y,%i1  

    sub %g2,0x1,%g2 
    brnz,pt %g2,mul_loop1 
    add %g1,0x10,%g1  ! move operand pointer 

    !********************************** 
    ! Operand2 as a register: MULScc 
    !********************************** 
#ifndef MULSCC_BUGS  
     mova %icc,%g3,%g1  ! same ops as mul_loop1 
    add %g0,NUM_MUL_CASES,%g2  
mulscc_1: 
    wr %g0,%g0,%ccr  ! ccr clear  
    ldx [%g1],%l1 
    ldx [%g1+8],%l2 
    wr %l1,0,%y  ! lower bits of multiplier into Y-reg 
    rd %y,%l0   ! for sas debug 
    srl %l1,0,%l1  ! clear rs1 upper 
    srl %l2,0,%l2  ! clear rs2 upper 
    mulx %l1,%l2,%l4  ! save for later compare 
    add %g0,0,%l1  ! clear rs1 (product upper) completely 

    add %g0,32,%l3  ! bit position counter 
mulscc_2: 
    sub %l3,1,%l3 
    mulscc %l1,%l2,%l1 
    brgez,pt %l3,mulscc_2 
    nop 

    sllx %l1,33,%l1  ! product upper 
    rd %y,%l3   ! product lower 
    or %l1,%l3,%l3  ! full product should be equal to mulx 
    subcc %l3,%l4,%l5 
    tnz T_BAD_TRAP 
    nop 

    sub %g2,0x1,%g2 
    brnz,pt %g2,mulscc_1 
    add %g1,0x10,%g1  ! move operand pointer 
#endif  

    !**************************************** 
    ! Operand2 as a register: SDIVX, UDIVX 
    !**************************************** 
    rdth_id    ! get thid in %o1 
    cmp %o1,0 
    be th_divx_0 
    cmp %o1,1 
    be th_divx_1 
    cmp %o1,2 
    be th_divx_2 
    nop 
    ba th_divx_3  ! if there are more than 4 threads... 
    nop 

th_divx_0: 
    setx divx_data_t0,%g7,%g1 
     ba all_threads2 
    nop 

th_divx_1: 
    setx divx_data_t1,%g7,%g1 
     ba all_threads2 
    nop 

th_divx_2: 
    setx divx_data_t2,%g7,%g1 
     ba all_threads2 
    nop 

th_divx_3: 
    setx divx_data_t3,%g7,%g1 
    ba all_threads2 
    nop 

all_threads2:  
    add %g0,NUM_DIV_CASES,%g2 

divx_loop1: 
    ldx [%g1],%l1 
    ldx [%g1+8],%l2 
    wr %g0,%g0,%ccr  ! ccr clear 

    sdivx %l1,%l2,%l3 
    udivx %l1,%l2,%l4 
    sdivx %l2,%l1,%l5  ! use each operand as divisor and dividend 
    udivx %l2,%l1,%l6 

    sub %g2,0x1,%g2 
    brnz,pt %g2,divx_loop1 
    add %g1,0x10,%g1  ! move operand pointer 
+1

我不知道你是否可以在某些模擬器中運行它,如果你可以破解仿真器給你的指令數運行(原諒我,如果這是沒有意義的) – Leo

+0

因此,你需要動態指令計數(執行總指令) ,而不是靜態insn計數(文件中的總insn; insn內部循環仍然只計數一次,即代碼大小)? –

+1

@Leo,你說得對,我在VCS Simulator上運行它,但我不知道該怎麼做/在哪裏做。 – user3285014

回答

1

我想一般瞭解的動態指令數是實際計數指令的儀表環境中運行代碼的唯一途徑。 (例如模擬器或具有perf計數器的CPU)。

我認爲一個程序,可以可靠地計算另一程序運行就等於解決Halting Problem的指令數。

在許多實際情況下,一個循環之後的分支將不依賴於循環計算的結果。如果循環結束條件很簡單,比如增加一個計數器到一個極限,那麼只需要將迭代*每個指令添加到一個總數並繼續前進。

這是不是一個簡單的問題;複雜性可能與編寫以asm作爲輸入的優化編譯器相似。你需要分析數據流來確定哪些分支將被採用,並且對於某些代碼你只需要模擬發生了什麼。

最好的辦法是幾乎可以肯定,只是找到一個模擬器/仿真器像@Leo說。

+0

很高興知道我不是說任何無意義的:-) – Leo