1.求绝对值函数
(1) _abs()
C代码 : int _abs(int src)
汇编: ABS
功能: 求32位数据的绝对值
(2) _labs()
C代码: int _labs(long src)
汇编: ABS
功能: 求40位数据的绝对值
(3) _abs2()
C代码: int _abs2(int src)
汇编: ABS2
功能: 同时求高16位和低16位的绝对值,即
return[31:16] = |src[31:16]|
return[15: 0] = |src[15: 0]|
2.运算指令
(1) _add2()
C代码: int _add2(int src1,int src2)
汇编: ADD2
功能: 同时进行src1,src2的高16位和src1,src2的低16位相加,忽略任何进位,即
return[31:16] = src1[31:16] + src2[31:16]
return[15: 0] = src1[15: 0] + src2[15: 0]
(2) _sadd()
C代码: int _sadd(int src1,int src2)
汇编: SADD
功能: 普通A+B的加法
(3) _lsadd()
C代码: long _lsadd(int src1,long src2)
汇编: SADD
功能: 32位数据加上40位数据,返回为40位数据
(4) _add4()
C代码: int _add4(int src1,int src2)
汇编: ADD4
功能: 同时进行src1和src2的每个对应Byte的4次加法,忽略任何进位,即
return[31:24] = src1[31:24] + src2[31:24]
return[23:16] = src1[23:16] + src2[23:16]
return[15: 8] = src1[15: 8] + src2[15: 8]
return[ 7: 0] = src1[ 7: 0] + src2[ 7: 0]
备注: src1,src2的每个8位数据当做signed数据使用
(5) _sadd2()
C代码: int _sadd2(int src1,int src2)
汇编: SADD2
功能: 同时进行src1,src2的高16位和低16位相加,忽略任何进位.即
return[31:16] = src1[31:16] + src2[31:16]
return[15: 0] = src1[15: 0] + src2[15: 0]
备注: src1,src2的每个16位数据被当做signed数据 (6) _saddus2()
C代码: int _saddus2(unsigned src1,int src2)
汇编: SADDUS2
功能: 执行和_sadd2一样的操作,但src1解释不同,见备注
备注: src1的每个16位数据被当作unsigned数据,src2的每个16位数据被当作signed数据 (7) _saddu4()
C代码: unsigned _saddu4(unsigned src1,unsigned src2)
汇编: SADDU4
功能: 执行和_add4()一样的操作,但数据解释为unsigned,限值为0xff
(8) _addsub()
C代码: long long _addsub(int src1,int src2)
汇编: ADDSUB
功能:同时进行src1 + src2和src1 - src2操作,即
hi32(return) = src1 + src2
low32(return) = src - src2
(9) _addsub2()
C代码: long long _addsub2(int src1,int src2)
汇编: ADDSUB2
功能: 同时进行_add2()和_sub2()操作,即
return[63:48] = hi16(src1) + hi16(src2)
return[47:32] = low16(src1) + low16(src2)
return[31:16] = hi16(src1) - hi16(src2)
return[15:0] = low16(src1) - low16(src2) (10) _saddsub()
C代码: long long _saddsub(unsigned src1,unsigned src2)
汇编: SADDSUB
功能: 同时执行add()和sub()操作,即
return[63:32] = src1 + src2
return[31:0] = src1 - src2
(11) _saddsub2()
C代码: long long _saddsub2(unsigned src1,unsigned src2)
汇编: SADDSUB2
功能: 同时进行sadd2()和ssub2()操作,即
return[63:48] = src1[31:16] + src2[31:16]
return[47:32] = src1[15: 0] + src2[15: 0]
return[31:16] = src1[31:16] - src2[31:16]
return[15: 0] = src1[15: 0] - src2[15: 0] (12) _ssub2()
C代码: int _ssub2(unsigned src1,unsigned src2)
汇编: SSUB2
功能: 同时进行高16位和低16位的减法,即
return[31:16] = src1[31:16] - src2[31:16]
return[15: 0] = src1[15: 0] - src2[15: 0] (13) _mpy2(),_mpy2ll
C代码: double(long long) _mpy2(int src1,int src2),long long _mpy2ll(int src1,int src2)
汇编:
功能:
(15) _mpyhi(),_mpyhill()
C代码: double _mpyhi(int src1,int src2),long long _mpyhill(int src1,int src2)
汇编: MPYHI
功能: 执行16位 * 32位操作,即
return = src1[31:16] * src2[31: 0] (15) _mpyli(),_mpylill()
C代码: double _mpyli(int src1,int src2),long long _mpylill(int src1,int src2)
汇编: MPYHI
功能: 执行16位 * 32位操作,即
return = src1[15: 0] * src2[31: 0] (16) _mpyhir()
C代码: int _mpyhir(int src1,int src2)
汇编: MPYHIR
功能: 执行(16位 * 32位 >> 15)操作,即
return = (src1[31:16] * src2[31: 0]) >> 15;
备注: 结果看起来被四舍五入了,例如0x1122 * 0x55667788结果应该是0x0b6e4b17,但仿真结果为0x0b6e4b18 (16) _mpylir()
C代码: int _mpylir(int src1,int src2)
汇编: MPYLIR
功能: 执行(16位 * 32位 >> 15)操作,即
return = (src1[15: 0] * src2[31: 0]) >> 15;
备注: 结果看起来被四舍五入了,例如0x1122 * 0x55667788结果应该是0x0b6e4b17,但仿真结果为0x0b6e4b18
(17) _mpy*u4(),_mpy*u4ll()
C代码: double _mpysu4(int src1,int src2),long long _mpysull4(int src1,int src2)
double _mpyu4(unsigned src1,unsigned src2),long long _mpyu4ll(unsigned src1,unsigned src2)
汇编: MPYSU4
MPYU4.M2X B4,A3,B5:A4
功能: 同时执行4个8位 * 8位操作,即
return[63:48] = src1[31:24] * src2[31:24];
return[47:32] = src1[23:16] * src2[23:16];
return[31:16] = src1[15: 8] * src2[15: 8];
return[15: 0] = src1[ 7: 0] * src2[ 7: 0];
(18) _smpy2(),_smpy2ll()
C代码: double _smpy2(int src1,int src2),long long _smpy2ll(int src1,int src2)
汇编: SMPY2
功能: 同时执行两个16位*16位操作,结果再左移1位,即
return = ((src1[31:16] * src2[31:16] << 32) + (src1[15: 0] * src2[15: 0])) << 1;
(19) _mpy32**()
C代码: int _mpy32(int src1,int src2),long long _mpy32ll(int src1,int src2)
long long _mpy32su(int src1,unsigned src2),long long _mpy32us(unsigned src1,int src2)
long long _mpy32u(unsigned src1,unsigned src2)
汇编: MPY32
MPY32SU.M2X B4,A3,B5:A4
MPY32US.M2X B4,A3,B5:A4
MPY32U.M2X B4,A3,B5:A4
功能: 执行32位 * 32位操作
(20) _mpy2ir()
C代码: long long _mpy2ir(int src1,int src2)
汇编: MPY2IR
功能: 返回如下结果
return[63:32] = src1[31:16] * src2 >> 15
return[31: 0] = src1[15: 0] * src2 >> 5
备注: 每一部分可能被四舍五入 (21) _gmpy()
C代码: unsignd _gmpy(unsigned src1,unsigned src2)
汇编: GMPY
功能: 执行"Galois Field multiply" (22) _smpy**()
C代码: int _smpy(int src1,int src2),int smpyh(int src1,int src2)
int _smpyhl(int src1,int src2),int _smpylh(int src1,int src2)
汇编: SMPY SMPYH
SMPYHL SMPYLH
功能: 执行16位*16位操作,结果再左移一位,限值结果为小于x80000000
_smpy: return[31: 0] = src1[15: 0] * src2[15: 0] << 1
_smpyh: return[31: 0] = src1[31:16] * src2[31:16] << 1
_smpyhl:return[31: 0] = src1[31:16] * src2[15: 0] << 1
_smpylh:return[31: 0] = src1[15: 0] * src2[31:16] << 1
(23) _mpy**()
C代码: int _mpy(int src1,int src2),int _mpyus(unsigned src1,int src2)
int _mpysu(int src1,unsigned src2),unsigned _mpyu(unsigned src1,unsigned src2)
汇编: MPY MPYUS
MPYSU MPYU
功能: 返回src1[15: 0] * src2[15: 0]的结果
(24) _mpyh**()
C代码: int _mpyh(int src1,int src2),int _mpyhus(unsigned src1,int src2)
int _mpyhsu(int src1,unsigned src2),int _mpyhu(unsigned src1,unsigned src2)
汇编: MPYH MPYHUS
MPYHSU MPYHU
功能: 返回src1[31:16] * src2[31:16]的结果
(25) _mpyh*l*()
C代码: int _mpyhl(int src1,int src2),int _mpyhuls(unsigned src1,int src2)
int _mpyhslu(int src1,unsigned src2),int _mpyhlu(unsigned src1,unsigned src2)
汇编: MPYHL MPYHULS
MPYHSLU MPYHLU
功能: 返回src1[31:16] * src2[15: 0]的结果
(26) _mpyl*h*()
C代码: int _mpylh(int src1,int src2),int _mpyluhs(unsigned src1,int src2)
int _mpylshu(int src1,unsigned src2),int _mpylhu(unsigned src1,unsigned src2)
汇编: MPYLH MPYLUHS
MPYLSHU MPYLHU
功能: 返回src1[15: 0] * src2[31: 16]的结果
(27) _*ssub()
C代码: int _ssub(int src1,int src2),long _lssub(int src1,int src2)
汇编: SSUB.L2X B4,A3,B4
功能: 执行src1 - src2操作,符号扩展为int或long
(28) _subc()
C代码:unsigned _subc(int src1,int src2)
汇编: SUBC
功能: 未知!! (29) _sub2()
C代码: int _sub2(int src1,int src2)
汇编: SUB2
功能: 同时执行高16位和低16位减法,即
return[31:16] = src1[31:16] - src2[31:16]
return[15: 0] = src1[15: 0] - src2[15: 0]
(30) _sub4()
C代码: int _sub4(int src1,int src2)
汇编: SUB4
功能: 同时执行4个8位减法,即
return[31:24] = src1[31:24] - src2[31:24]
return[23:16] = src1[23:16] - src2[23:16]
return[15: 8] = src1[15: 8] - src2[15: 8]
return[ 7: 0] = src1[ 7: 0] - src2[ 7: 0]
(31) _subabs4()
C代码: int _subabs4(int src1,int src2)
汇编: SUBABS4
功能: 同时执行4个8位减法,再求绝对值,即
return[31:24] = |src1[31:24] - src2[31:24]|
return[23:16] = |src1[23:16] - src2[23:16]|
return[15: 8] = |src1[15: 8] - src2[15: 8]|
return[ 7: 0] = |src1[ 7: 0] - src2[ 7: 0]|
(32) _avg2()
C代码: int _avg2(int src1,int src2)
汇编: AVG2
功能: 计算两路16位平均值,四舍五入结果
return[31:16] = (src1[31:16] + src2[31:16] + 1) / 2;
return[15: 0] = (src1[15: 0] + src2[15: 0] + 1) / 2;
(33) _avgu4()
C代码: int _avgu4(int src1,int src2)
汇编: AVGU4
功能: 计算四路8位平均值,四舍五入结果
return[31:24] = (src1[31:24] + src2[31:24] + 1) / 2;
return[23:16] = (src1[23:16] + src2[23:16] + 1) / 2;
return[15: 8] = (src1[15: 8] + src2[15: 8] + 1) / 2;
return[ 7: 0] = (src1[ 7: 0] + src2[ 7: 0] + 1) / 2;
3.位操作指令
(1) _clr()
C代码: int _clr(unsined src,unsigned csta,unsigned cstb)
汇编: CLR
功能: 清除src上的位csta ~ 位cstb,即
src[cstb:csta] = 0;
备注: csta必须 <= cstb,且保证 < 32 (2) _clrr()
C代码: int _clrr(unsigned src,int shift)
汇编: CLR
功能: 清除src上的shift[ 9: 5] ~ shift[ 4: 0]位
(3) _set()
C代码: int _set(unsined src,unsigned csta,unsigned cstb)
汇编: SET
功能: 设置src上的位csta ~ 位cstb,即
src[cstb:csta] = '1';
备注: csta必须 <= cstb,且保证 < 32
(4) _setr()
C代码: int _setr(unsigned src,int shift)
汇编: SET
功能: 设置src上的shift[ 9: 5] ~ shift[ 4: 0]位为'1'
(5) _sshl()
C代码: int _sshl(int src,unsigned shift)
汇编: SSHL
功能: return[31: 0] = src << shift;
备注: 有符号扩展功能
(6) _rotl()
C代码: int _rotl(unsigned src,unsigned shift
汇编: ROTL
功能: return[31: 0] = src << shift;
备注: 无符号扩展功能
(7) __shlmb(),__shrmb()
C代码: int _shlmb(int src1,int src2),int _shrmb(int src1,int src2)
汇编: SHLMB
功能: shlmb-->return[31:0] = (src2 << 8) | src1[31:24]
shrmb-->return[31:0] = (src2 >> 8) | (src1[7: 0] << 24)
(8) __shr2(),_shru2()
C代码: int _shr2(int src1,unsigned shift),int _shru2(unsigned src1,unsigned shift)
汇编: SHR2
功能: return[31: 16] = src1[31:16] >> shift
return[15: 0] = src1[15: 0] >> shift
备注: 有符号数操作返回值会进行符号扩展(移出的位全部补1)
(9) _sshvl(),_sshvr()
C代码: int _sshvl(int src,int shift),int _sshvr(int src,int shift)
汇编: SSHVL SSHVR
功能: sshvl-->return[31: 0] = (src << shift) > MAX_INT?MAX_INTsrc << shift)
sshvr-->return[31: 0] = (src >> shift) < MIN_INT?MIN_INTsrc >> shift)
(10) _shfl()
C代码: int _shfl(int src)
汇编: SHFL
功能: 低16位嵌入到偶位,高16位嵌入到奇位,即
return[31:0] = src[31]src[15]src[30]src[14]........src[16][src[0]
(11) _ext()
C代码: int _ext(int src,unsigned lshift,unsigned rshift)
汇编: EXT
功能: return[31: 0] = (src << lshift) >> rshift;
(12) _extr()
C代码: int _extr(int src,int shift)
汇编: EXT
功能: return[31: 0] = (src << shift[ 9: 5]) >> shift[4: 0];
(13) _extu()
C代码: int _extu(int src,unsigned lshift,unsigned rshift)
汇编: EXT
功能: return[31: 0] = (src << lshift) >> rshift;
(14) _extur()
C代码: int _extur(int src,int shift)
汇编: EXT
功能: return[31: 0] = (src << shift[ 9: 5]) >> shift[4: 0];
(15) _lmbd()
C代码: unsigned _lmbd(int zero_or_one,int src)
汇编: LMBD
功能: 从左到右查找该位是zero_or_one的位,返回该位置
备注:
zero_or_one必须为0或者1,为其他值无LMBD指令编译
如src = 0x0fff0000,则
_lmbd(0,src) == 0 /*D31为'0',所以返回0*/
_lmbd(1,src) == 4 /*D27为'1',所以返回4*/
(16) _*norm()
C代码: unsigned _norm(int src),unsignd _lnorm(long src)
汇编: NORM B4,B4
功能: 未知 (17) _bitc4()
C代码: unsigned _bitc4(unsigned src)
汇编: BITC4
功能: 统计每个字节的'1'总数,4个总数合成unsigned返回
备注:
例如src = 0x01030507,因为4个字节分别有0x01,0x02,0x03,0x04个'1',所以返回为0x01020304
(18) _bitr()
C代码: unsigned _bitr(unsigned src)
汇编: BITR
功能: 反转所有的位,即return[31:0] = src[ 0:31]
备注:
例如src = '00010001000100010001000100010001',则返回值是'10001000100010001000100010001000'
(19) _deal()
C代码: unsigned _deal(unsigned src)
汇编: DEAL
功能: 所有偶位组合成一个16位数据,所有奇位组合成一个16位数据,返回该32位值,即
return[31:16] = src[31,29,27,....,1]
return[15: 0] = src[30,28,26,....,0] 4.内存操作指令
(1) _amem*()
C代码: ushort& _amem2(void* ptr),const ushort _amem2_const(void* ptr)
unsigned& _amem4(void* ptr),const unsigned& _amem4_const(void* ptr)
long long _amem8(void* ptr),const long long& _amem8_const(void* ptr)
double & _amemd8(void* ptr),const double& _amemd8_const(void* ptr)
汇编: 略
功能: 从对齐地址中读/写n字节数据,n = 以上的数字
备注:
读--->
double val;
char test[8] = {0,1,2,3,4,5,6,7};
val = _amem2_const(&test) + _amem4_const(&test) + _amem8_const(&test);
写--->
_amem2(&test) = 0x0011;
_amem4(&test) = 0x00112233;
_amem8(&test) = 0x0011223344556677;
(2) _mem*()
C代码: ushort& _mem2(void* ptr),const ushort _mem2_const(void* ptr)
unsigned& _mem4(void* ptr),const unsigned& _mem4_const(void* ptr)
long long _mem8(void* ptr),const long long& _mem8_const(void* ptr)
double & _memd8(void* ptr),const double& _memd8_const(void* ptr)
汇编: 略
功能: 从非对齐地址中读/写n字节数据,n = 以上的数字
备注:
读--->
double val;
char test[8] = {0,1,2,3,4,5,6,7};
val = _mem2_const(&test) + _mem4_const(&test) + _mem8_const(&test);
写--->
_mem2(&test) = 0x0011;
_mem4(&test) = 0x00112233;
_mem8(&test) = 0x0011223344556677; (3) _mvd()
C代码: int _mvd(int src)
汇编: MVD
功能: 利用4周期乘法流水线拷贝数据,return[31: 0] = src[31: 0]
备注: 这个需要和_mpy**()配合实现并行工作 5.数据包装/转换指令
(1) _hi**()
C代码: unsigned _hi(double src),unsigned _hill(long long src)
汇编: 无
功能: 返回64位数据的高32位数据
(2) _low**()
C代码: unsigned _lo(double src),unsigned _loll(long long src)
汇编: 无
功能: 返回64位数据的低32位数据
(3) _*to*()
C代码: ulong _dtol(double src),unsigned _ftoi(float src)
double _itod(unsigned hi32,unsigned low32),float _itof(unsigned src)
long long _itoll(unsigned hi32,unsigned low32),double _ltod(long src)
汇编: 无
功能: 各种数据类型互相转换
(4) _sat()
C代码: int _sat(long src2)
汇编: SAT
功能: 把40位long数据转成32位数据
(5) _pack*2()
C代码: unsigned _pack2(unsigned src1,unsigned src2),
unsigned _packh2(unsigned src1,unsigned src2)
汇编: PACK2 PACKH2
功能: _pack2--->return[31:16] = src1[15: 0],return[15: 0] = src2[15: 0]
_packh2-->return[31:16] = src1[31: 16],return[15: 0] = src2[31: 16]
(6) _pack*4()
C代码: unsigned _packh4(unsigned src1,unsigned src2),
unsigned _packl4(unsigned src1,unsigned src2)
汇编: PACKH4 PACKL4
功能: 返回交替的4字节数据
备注: 如src1 = 0x11223344,src2 = 0x55667788,则
_packh4(src1,src2)返回0x11335577
_packl4(src1,src2)返回0x22446688
(7) _pack**2()
C代码: unsigned _packhl2(unsigned src1,unsigned src2),
unsigned _packlh2(unsigned src1,unsigned src2)
汇编: PACKHL2 PACKLH2
功能: _packhl2--->return[31:16] = src1[31: 16],return[15: 0] = src2[15: 0]
_packlh2-->return[31:16] = src1[15: 0],return[15: 0] = src2[31: 16] (8) _spack2()
C代码: int _spack2(int src1,int src2)
汇编: SPACK2
功能: 把两个32位数据格式化成16位数据,然后组合成32位数据
备注: return[31: 16] = (int16_t)src1
return[15: 0] = (int16_t)src2
(9) _spacku4()
C代码: unsigned _spacku4(int src1,int src2)
汇编: SPACKU4
功能: 把4个16位数据格式化成4个8位数据,形成32位数据返回
备注: return[31:24] = (unt8_t)src1[31:16]
return[23:16] = (unt8_t)src1[15: 0]
return[15: 8] = (unt8_t)src2[31:16]
return[ 7: 0] = (unt8_t)src1[15: 0]
(10) _swap4()
C代码: unsigned _swap(unsigned src)
汇编: SWAP4
功能: 大小端数据转换
备注: return[31:24] 和 return[23:16] 交换
return[15: 8] 和 return[ 7: 0] 交换
(11) _unpkhu4()
C代码: unsigned _unpkhu4(unsigned src)
汇编: UNPKHU4
功能: 把两个高8位数据转成两个16位数据
备注:
return[31:16] = (uint16_t)src[31:24]
return[15: 0] = (uint16_t)src[23:16]
(12) _unpklu4()
C代码: unsigned _unpklu4(unsigned src)
汇编: UNPKHU4
功能: 把两个低8位数据转成两个16位数据
备注:
return[31:16] = (uint16_t)src[15: 8]
return[15: 0] = (uint16_t)src[ 7: 0]
6.比较/杂项指令
(1) _cmpeq*() _cmpgt*()
C代码: int _cmpeq2(int src1,int src2),int _cmpeq4(int src1,int src2)
int _cmpgt2(int src1,int src2),int _cmpgtu4(unsigned src1,unsigned src2)
汇编: CMPEQ2 CMPEQ4
CMPGT2 CMPGT4
功能: 同时比较两个16位数据或者4个8位数据,比较结果在返回值的低2位或低四位中
备注:
_cmpeq2(0x11223344,0x11220000)返回为0x02
_cmpeq4(0x11223344,0x00223344)返回为0x07
_cmpgt2(0x00001111,0x0000ffff)返回为0x01
_cmpgtu4(0x0000ffff,0x0000aaaa)返回0x03
(2) _xpnd*()
C代码: int _xpnd2(int src),int _xpnd4(int src)
汇编: XPND2 XPND4
功能: _xpnd2()把src的低2位逻辑值扩展为2个16位逻辑值
_xpnd4()把src的低4位逻辑值扩展为4个8位逻辑值
备注:
_xpnd*()一般和_cmp*()配合实现逻辑扩展
_xpnd2(0x01) = 0x0000ffff
_xpnd2(0x03) = 0xffffffff
_xpnd2(0x00) = 0x00000000
_xpnd4(0x00) = 0x00000000
_xpnd4(0x08) = 0xff000000
_xpnd4(0x07) = 0x00ffffff
_xpnd4(0x01) = 0x000000ff
|