Floating-point operations (6) in VDSP (bf561): float plus minus operation

Source: Internet
Author: User

Always thought float subtraction operation is very simple, is to convert it to __float32_add and __float32_sub These two function calls, and then use software simulation to add and subtract operations. But is it really that simple? Is it still the case when some uncomfortable conditions come into being?

Processing of 1.1 VDSP on float addition and subtraction operation

Under VDSP, you can easily use:

float add(float x, float y)
{
float r = x + y;
return r;
}
float sub(float x, float y)
{
float r = x - y;
return r;
}

To complete the floating-point addition and subtraction operation, the compiler automatically converts the addition operation inside into a ___float32_add function call, and converts the subtraction operation to a ___float32_sub function call, which is implemented in LIBDSP/FPADD.ASM:

___float32_sub:
BITTGl (R1,31);  // Flip sign bit of Y, fall through to add
.align 2;
___float32_add:

From these lines of code you can see that subtraction is simply the addition of the meiosis symbol.

1.2 When Y is 0 o'clock

Look at the __float32_add code:

// check for addition of 0.0
R3 = R1 << 1;  // Remove sign
CC = R3;    // If Y=0, return X
IF !CC JUMP .return_x_nopop;
………..
.return_x_nopop:
#if CHECKING_FOR_NEGZERO_RES
R1 = R0 << 1;
CC = R1;
IF !CC R0 = R1; // convert any -0.0 to 0.0
#endif
RTS;

Returns the value of x directly, at which point the number of cycle required is 25.

1.3 When x is 0 o'clock

R2 = R0 << 1;  // Remove sign
CC = R2;    // If X=0, return Y
IF !CC JUMP .return_y_nopop;
……….
.return_y_nopop:
R0 = R1;
RTS;

Returns the value of Y directly, at which point the number of cycle required is 26.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.