产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
根据mask对源操作数srcReg0、srcReg1进行按元素相减操作,将结果写入目的操作数dstReg。计算公式如下:

若srcReg0,srcReg1相减产生借位结果时,在MaskReg carry中对应位置每4bit的最低位写0,否则写1。
具体的示例如下:
数据类型 |
是否借位 |
示例说明 |
|---|---|---|
int32_t数据类型 |
不产生借位 |
a_i = 5, b_i = 2 dst_i = a_i - b_i = 3 carry中对应位置每4bit的最低位写1:carry_i = 1 |
产生借位 |
a_i = 5, b_i = -7 dst_i = a_i - b_i = 12 carry中对应位置每4bit的最低位写0:carry_i = 0 |
|
uint32_t数据类型 |
不产生借位 |
a_i = 5, b_i = 2, dst_i = a_i - b_i = 3 carry中对应位置每4bit的最低位写1:carry_i = 1 |
产生借位 |
a_i = 5, b_i = 7 dst_i = a_i - b_i = -2 carry中对应位置每4bit的最低位写0:carry_i = 0 |
template <typename T = DefaultType, MaskMergeMode mode = MaskMergeMode::ZEROING, typename U> __simd_callee__ inline void Sub(U& dstReg, U& srcReg0, U& srcReg1, MaskReg& mask)
template <typename T = DefaultType, typename U> __simd_callee__ inline void Sub(MaskReg& carry, U& dstReg, U& srcReg0, U& srcReg1, MaskReg& mask)
参数名 |
描述 |
|---|---|
T |
操作数数据类型。 Ascend 950PR/Ascend 950DT,支持的数据类型为:uint8_t/int8_t/uint16_t/int16_t/uint32_t/int32_t/half/float/bfloat16_t/uint64_t/int64_t/complex32/complex64 |
mode |
选择MERGING模式或ZEROING模式。
|
U |
目的操作数的RegTensor类型,例如RegTensor<half>,由编译器自动推导,用户不需要填写。 |
无
无
template<typename T>
__simd_vf__ inline void SubVF(__ubuf__ T* dstAddr, __ubuf__ T* src0Addr, __ubuf__ T* src1Addr, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes)
{
AscendC::Reg::RegTensor<T> srcReg0;
AscendC::Reg::RegTensor<T> srcReg1;
AscendC::Reg::RegTensor<T> dstReg;
AscendC::Reg::MaskReg mask;
for (uint16_t i = 0; i < repeatTimes; i++) {
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::LoadAlign(srcReg0, src0Addr + i * oneRepeatSize);
AscendC::Reg::LoadAlign(srcReg1, src1Addr + i * oneRepeatSize);
AscendC::Reg::Sub(dstReg, srcReg0, srcReg1, mask);
AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
}
}
template <typename T>
__simd_vf__ inline void SubVF(__ubuf__ T* dst0Addr, __ubuf__ T* dst1Addr, __ubuf__ T* src0Addr, __ubuf__ T* src1Addr, uint32_t count, uint32_t repeatTimes, uint16_t oneRepeatSize){
AscendC::Reg::RegTensor<T> srcReg0;
AscendC::Reg::RegTensor<T> srcReg1;
AscendC::Reg::RegTensor<T> dstReg0;
AscendC::Reg::MaskReg mask;
AscendC::Reg::MaskReg carry = AscendC::Reg::CreateMask<uint8_t>();
for (uint16_t i = 0; i < repeatTimes; i++) {
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::LoadAlign(srcReg0, src0Addr + i * oneRepeatSize);
AscendC::Reg::LoadAlign(srcReg1, src1Addr + i * oneRepeatSize);
AscendC::Reg::Sub(carry, dstReg0, srcReg0, srcReg1, mask);
// 8*4B=32B align
AscendC::Reg::StoreAlign<uint32_t, AscendC::Reg::MaskDist::DIST_NORM>((__ubuf__ uint32_t*)dst1Addr + i * 8, carry);
AscendC::Reg::StoreAlign(dst0Addr + i * oneRepeatSize, dstReg0, mask);
}
}