WO2021056507A1 - Method for processing floating point number, device, and mobile platform - Google Patents

Method for processing floating point number, device, and mobile platform Download PDF

Info

Publication number
WO2021056507A1
WO2021056507A1 PCT/CN2019/108872 CN2019108872W WO2021056507A1 WO 2021056507 A1 WO2021056507 A1 WO 2021056507A1 CN 2019108872 W CN2019108872 W CN 2019108872W WO 2021056507 A1 WO2021056507 A1 WO 2021056507A1
Authority
WO
WIPO (PCT)
Prior art keywords
value
data segment
floating
calculation mode
calculation
Prior art date
Application number
PCT/CN2019/108872
Other languages
French (fr)
Chinese (zh)
Inventor
徐功林
刘子男
韩彬
Original Assignee
深圳市大疆创新科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市大疆创新科技有限公司 filed Critical 深圳市大疆创新科技有限公司
Priority to CN201980033559.5A priority Critical patent/CN112189184A/en
Priority to PCT/CN2019/108872 priority patent/WO2021056507A1/en
Publication of WO2021056507A1 publication Critical patent/WO2021056507A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/38Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
    • G06F7/48Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
    • G06F7/483Computations with numbers represented by a non-linear combination of denominational numbers, e.g. rational numbers, logarithmic number system or floating-point numbers
    • G06F7/487Multiplying; Dividing
    • G06F7/4876Multiplying

Definitions

  • the embodiments of the present application relate to the field of data processing technology, and in particular, to a floating-point number processing method, device, and movable platform.
  • floating-point number is a digital representation of a certain subset of rational numbers, which is used to approximate any real number in a computer.
  • Floating-point calculations refer to operations involving floating-point numbers, which are usually accompanied by approximation or rounding.
  • floating-point numbers are also required to perform some non-linear operations, such as calculating the reciprocal, calculating the square root, and calculating the reciprocal square root. .
  • nonlinear calculation process is more complicated, it takes up more processing resources, which reduces the processing efficiency.
  • the embodiments of the present application provide a floating-point number processing method, device, and a movable platform, which improve the operating efficiency of floating-point numbers and reduce hardware costs.
  • an embodiment of the present application provides a floating-point number processing method, including:
  • the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
  • the first value is found in a preset value table corresponding to the calculation mode, and the preset value table includes the value of the high-order sub-data segment and calculated by a first calculation formula Correspondence of the results obtained;
  • the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the address of the mantissa data segment corresponding to the operation result of the floating-point number in the calculation mode ;
  • the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
  • an embodiment of the present application provides a floating-point number processing device, including: a processor, an addition unit, a first multiplier, a first storage device, and a second storage device;
  • the first storage device is used to store floating-point numbers and calculation results of floating-point numbers in calculation mode
  • the second storage device is used to store preset value tables corresponding to different calculation modes respectively;
  • the processor is used to:
  • the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
  • the first value is obtained by looking up the preset value table corresponding to the calculation mode stored in the second storage device, and the preset value table includes the value of the high-order sub-data segment. Correspondence between the value and the result calculated by the first calculation formula;
  • the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the second storage device corresponding to the float The address of the mantissa data segment of the operation result of the point in the calculation mode;
  • the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
  • an embodiment of the present application provides a movable platform, including: a movable platform body and the floating-point number processing device according to the embodiment of the present application in the first aspect, wherein the floating-point number processing device is installed in the On the movable platform body.
  • an embodiment of the present application provides a readable storage medium with a computer program stored on the readable storage medium; when the computer program is executed, it implements the float described in the embodiment of the present application in the first aspect. Point processing method.
  • an embodiment of the present application provides a program product, the program product includes a computer program, the computer program is stored in a readable storage medium, and at least one processor of a removable platform can download from the readable storage medium The computer program is read, and the at least one processor executes the computer program to enable the mobile platform to implement the floating-point number processing method described in the embodiment of the present application in the first aspect.
  • the first value is obtained by looking up the value of the upper sub-data segment in the mantissa data segment of the floating-point number in the preset value table corresponding to the calculation mode
  • the preset value table includes the corresponding relationship between the value of the high-order sub-data segment and the result calculated by the first calculation formula; and the value of the high-order sub-data segment and the value of the low-order sub-data segment in the mantissa data segment
  • the numerical value is input to the addition unit, so that the addition unit performs an operation according to the addition formula corresponding to the calculation mode to obtain a second value; then the first value and the second value are input to the first multiplier, Obtain the first product result; and then, according to the first product result, obtain the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode; wherein the product of the first operation formula and the addition operation formula , Constitute the polynomi
  • the preset value table of the higher sub-data segment in the mantissa data segment corresponding to different types of calculation modes is pre-stored, instead of the preset value table corresponding to the entire mantissa data segment, which reduces the storage capacity of the preset value table. Improved the speed of checking the preset value table.
  • different types of calculation modes reuse addition units and multipliers, and perform simple linear operations to obtain the results of various types of nonlinear complex operations, reduce hardware costs, and improve computing efficiency.
  • Fig. 1 is a schematic architecture diagram of an unmanned aerial system according to an embodiment of the present application
  • FIG. 2 is a flowchart of a floating-point number processing method provided by an embodiment of the application
  • FIG. 3 is a schematic diagram of a format of a floating point number provided by an embodiment of the application.
  • FIG. 4 is a schematic diagram of the high-order sub-data segment and the low-order sub-data segment in the mantissa data segment of a floating-point number provided by an embodiment of the application;
  • FIG. 5 is a schematic diagram of the hardware architecture provided by an embodiment of the application.
  • FIG. 6 is a schematic structural diagram of a floating-point number processing device provided by an embodiment of the application.
  • FIG. 7 is a schematic structural diagram of a movable platform provided by an embodiment of this application.
  • FIG. 8 is a schematic structural diagram of a movable platform provided by another embodiment of the application.
  • the embodiments of the present application provide floating-point number processing methods, equipment, and mobile platforms, where the mobile platforms can be handheld phones, handheld PTZ, unmanned aerial vehicles, unmanned vehicles, unmanned ships, robots, or self-driving cars, etc. .
  • the following description of the mobile platform of this application uses drones as an example. It will be obvious to those skilled in the art that other types of drones can be used without restriction, and the embodiments of the present application can be applied to various types of drones.
  • the drone can be a small or large drone.
  • the drone may be a rotorcraft, for example, a multi-rotor drone that is propelled by multiple propulsion devices through the air.
  • the embodiments of the present application are not limited to this, and the drone It can also be other types of drones.
  • Fig. 1 is a schematic architecture diagram of an unmanned aerial system according to an embodiment of the present application.
  • a rotary wing drone is taken as an example for description.
  • the unmanned aerial system 100 may include a drone 110, a display device 130, and a remote control device 140.
  • the UAV 110 may include a power system 150, a flight control system 160, a frame, and a pan/tilt 120 carried on the frame.
  • the drone 110 can wirelessly communicate with the remote control device 140 and the display device 130.
  • the frame may include a fuselage and a tripod (also called a landing gear).
  • the fuselage may include a center frame and one or more arms connected to the center frame, and the one or more arms extend radially from the center frame.
  • the tripod is connected with the fuselage, and is used for supporting the UAV 110 when it is landed.
  • the power system 150 may include one or more electronic governors (referred to as ESCs) 151, one or more propellers 153, and one or more motors 152 corresponding to the one or more propellers 153, wherein the motors 152 are connected to Between the electronic governor 151 and the propeller 153, the motor 152 and the propeller 153 are arranged on the arm of the UAV 110; the electronic governor 151 is used to receive the driving signal generated by the flight control system 160 and provide driving according to the driving signal Current is supplied to the motor 152 to control the speed of the motor 152.
  • the motor 152 is used to drive the propeller to rotate, thereby providing power for the flight of the drone 110, and the power enables the drone 110 to achieve one or more degrees of freedom of movement.
  • the drone 110 may rotate about one or more rotation axes.
  • the aforementioned rotation axis may include a roll axis (Roll), a yaw axis (Yaw), and a pitch axis (pitch).
  • the motor 152 may be a DC motor or an AC motor.
  • the motor 152 may be a brushless motor or a brushed motor.
  • the flight control system 160 may include a flight controller 161 and a sensing system 162.
  • the sensing system 162 is used to measure the attitude information of the drone, that is, the position information and state information of the drone 110 in space, such as three-dimensional position, three-dimensional angle, three-dimensional velocity, three-dimensional acceleration, and three-dimensional angular velocity.
  • the sensing system 162 may include, for example, at least one of sensors such as a gyroscope, an ultrasonic sensor, an electronic compass, an inertial measurement unit (IMU), a vision sensor, a global navigation satellite system, and a barometer.
  • the global navigation satellite system may be the Global Positioning System (GPS).
  • the flight controller 161 is used to control the flight of the drone 110, for example, it can control the flight of the drone 110 according to the attitude information measured by the sensor system 162. It should be understood that the flight controller 161 can control the drone 110 according to pre-programmed program instructions, and can also control the drone 110 by responding to one or more remote control signals from the remote control device 140.
  • the pan/tilt head 120 may include a motor 122.
  • the pan/tilt is used to carry the camera 123.
  • the flight controller 161 can control the movement of the pan/tilt 120 through the motor 122.
  • the pan/tilt head 120 may further include a controller for controlling the movement of the pan/tilt head 120 by controlling the motor 122.
  • the pan-tilt 120 may be independent of the drone 110 or a part of the drone 110.
  • the motor 122 may be a DC motor or an AC motor.
  • the motor 122 may be a brushless motor or a brushed motor.
  • the pan-tilt can be located on the top of the drone, or on the bottom of the drone.
  • the photographing device 123 may be, for example, a device for capturing images, such as a camera or a video camera, and the photographing device 123 may communicate with the flight controller and take pictures under the control of the flight controller.
  • the imaging device 123 of this embodiment at least includes a photosensitive element, and the photosensitive element is, for example, a Complementary Metal Oxide Semiconductor (CMOS) sensor or a Charge-coupled Device (CCD) sensor. It can be understood that the camera 123 can also be directly fixed to the drone 110, so the pan/tilt 120 can be omitted.
  • CMOS Complementary Metal Oxide Semiconductor
  • CCD Charge-coupled Device
  • the display device 130 is located on the ground end of the unmanned aerial system 100, can communicate with the drone 110 in a wireless manner, and can be used to display the attitude information of the drone 110.
  • the image photographed by the photographing device 123 may also be displayed on the display device 130. It should be understood that the display device 130 may be an independent device or integrated in the remote control device 140.
  • the remote control device 140 is located on the ground end of the unmanned aerial system 100, and can communicate with the drone 110 in a wireless manner for remote control of the drone 110.
  • the processing of floating-point numbers when processing the image taken by the above-mentioned photographing device 123, the processing of floating-point numbers is involved, and the processing of floating-point numbers can refer to the relevant descriptions in the following embodiments. It should be noted that the processing of floating-point numbers is not limited to the above-mentioned application scenarios, and can also be applied to related fields such as sensors, image transmission, and intelligent driving. The processing of floating-point numbers can all adopt the solutions of the embodiments of the present application.
  • Fig. 2 is a flowchart of a floating-point number processing method provided by an embodiment of the application. As shown in Fig. 2, the method of this embodiment may include:
  • the floating-point number includes a mantissa data segment
  • the floating-point number can also include a sign data segment and an exponent data segment, as shown in FIG. 3, where the sign data segment (s) is a 1-bit (sign) bit. ), the exponent data segment (Exponent) is an 8-bit exponent bit (e), and the mantissa data segment (Mantissa) is a 23-bit decimal place (m).
  • the mantissa data segment omits the implicit bit 1, namely Mantissa
  • the actual representation is 1.m. Therefore, the value represented by the normalized floating point number is:
  • a processing instruction for a floating-point number is acquired.
  • the processing instruction is used to indicate a calculation mode of the floating-point number. ), or, calculate the square root (e.g. calculate ), or to calculate the reciprocal of the root (for example, to calculate ), this embodiment is not limited to this.
  • the floating-point number processing instruction can be an instruction determined in the process of processing the data. If the floating-point number needs to be reciprocated, it is determined that the obtained calculation mode for indicating the floating-point number is the processing instruction for calculating the reciprocal. ; If it is necessary to perform square root operation on a floating-point number, it is determined that the processing instruction used to indicate that the calculation mode of the floating-point number is the calculation square root is obtained; if it is necessary to perform the reciprocal square root operation on the floating-point number, it is determined to obtain The calculation mode used to indicate the floating-point number is a processing instruction for calculating the reciprocal of the root.
  • S202 At the storage address of the mantissa data section, read the high-order sub-data section and the low-order sub-data section of the mantissa data section respectively.
  • the storage address of the mantissa data segment of the floating-point number is determined, and then the mantissa data segment is read at the storage address of the mantissa data segment, where the reading of this embodiment
  • the method is to read the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment respectively.
  • the first value is obtained by searching in the preset value table of the corresponding calculation mode.
  • preset value tables corresponding to different calculation modes are pre-stored, that is, the preset value tables corresponding to different calculation modes may be different.
  • this embodiment has three preset value tables pre-stored, namely: the preset value table corresponding to the reciprocal calculation, and the one corresponding to the calculation root.
  • Preset value table corresponding to the preset value table for calculating the reciprocal root.
  • the preset value table includes the corresponding relationship between the value of the upper sub-data segment of each floating-point number and the result calculated by the first calculation formula.
  • the first calculation formula may be different.
  • the first value is obtained from the preset value table corresponding to the calculation mode according to the value of the high-order sub-data segment.
  • the value of the data segment is calculated by the first calculation formula.
  • the addition unit calculates according to the corresponding
  • the addition formula of the pattern is to perform operations on the value of the upper sub-data segment and the data of the lower sub-data segment to obtain the second value.
  • the corresponding addition operation formula may be different.
  • the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
  • the first value and the second value are input to the multiplier.
  • the multiplier is called the first multiplier.
  • the first multiplier combines the first value with the second value. Multiply to obtain a product result, which is called the first product result.
  • S206 Obtain the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the first product result, and store the mantissa data segment address of the operation result of the corresponding floating-point number in the calculation mode.
  • the value of the mantissa data section of the operation result of the floating-point number in the calculation mode is obtained, and the value of the mantissa data section of the operation result of the floating-point number in the calculation mode is stored. Enter the address of the mantissa data segment corresponding to the operation result of the floating-point number in this calculation mode.
  • the first value is found in the preset value table corresponding to the calculation mode according to the value of the upper sub-data segment in the mantissa data segment of the floating-point number, and the preset value table includes the upper sub-data.
  • the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained; wherein, the product of the first operation formula and the addition operation formula constitutes Taylor of the function expression corresponding to the calculation mode The polynomial part of the expansion.
  • the preset value table of the higher sub-data segment in the mantissa data segment corresponding to different types of calculation modes is pre-stored, instead of the preset value table corresponding to the entire mantissa data segment, which reduces the storage capacity of the preset value table. Improved the speed of checking the preset value table.
  • different types of calculation modes reuse addition units and multipliers, and perform simple linear operations to obtain the results of various types of nonlinear complex operations, reduce hardware costs, and improve computing efficiency.
  • the sum of the number of bits in the high-order sub-data segment and the number of low-order sub-data bits of the mantissa data segment is equal to the number of bits in the mantissa data segment.
  • the number of bits in the upper sub-data segment and the number of bits in the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion. For example: if the precision of the remainder part is less than or equal to 2-18, the number of bits in the upper sub-data segment is 9. Because in the calculation of the calculation result in the calculation mode, the remainder part corresponding to the Taylor expansion is omitted, so the accuracy of the remainder part is actually related to the accuracy of the calculation result. Therefore, in this embodiment, the accuracy of the calculation result can be adjusted according to actual needs.
  • the above-mentioned addition operation unit includes a selector and an adder. Accordingly, a possible implementation of the above-mentioned S204 may include S2041 and S2042:
  • the numerical value of the low-order sub-data segment is input into the selector, and the selector assigns the numerical value of the low-order sub-data segment to the calculation coefficient corresponding to the calculation mode to obtain the third value, wherein, for different types of calculation modes ,
  • the calculation coefficients assigned to the lower sub-data bits may be different.
  • the third value is multiplied by the value of the lower sub-data segment as the third value.
  • the numerical value of the high-order sub-data segment and the third value are input to the adder, and the adder adds the numerical value of the high-order sub-data segment to the third value, and the value obtained by the addition is used as the second value.
  • this embodiment multiplexes selectors, adders, and multipliers, and performs simple addition and multiplication operations to obtain results of various types of nonlinear complex operations, reduces hardware costs, and improves operation efficiency.
  • the first calculation formula is The addition operation formula is a+(-1)t. If the calculation mode includes a square root, the first calculation formula is The addition operation formula is If the calculation mode includes calculating the reciprocal root, the first calculation formula is The addition operation formula is Wherein, a is the value of the upper sub-data segment, and t is the value of the lower sub-data segment.
  • the selector may include calculating the reciprocal according to the calculation mode, the calculation coefficient assigned to t is -1, and the third value is (-1)t; the selector may include calculating the square root according to the calculation mode, and the selection is assigned to t n The calculation coefficient is Get the third value
  • the selector can include calculating the reciprocal root of the square according to the calculation mode, and select the calculation coefficient given to t as Get the third value
  • a possible implementation manner of obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the first product result in the foregoing S205 may include S2051-S2052:
  • the preset number of bits is the number of bits in the mantissa data segment, and the number of bits in the mantissa data segment is, for example, 23 bits.
  • the above-mentioned first preset value is, for example, 1.
  • a possible implementation manner of the foregoing S2052 may be:
  • the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating point number in the calculation mode. That is, the value of the K+1 to K+23 in the order from high to low in the first product result is determined as the value of the mantissa data segment of the operation result of the floating-point number under the reciprocal calculation .
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the floating-point number is obtained in the calculation mode according to the parity of the value of the exponent data segment of the floating-point number and the value of the preset number of bits.
  • the value of the mantissa data field of the operation result below.
  • the calculation mode is calculation root, if the value of the exponent data segment of the floating-point number is an odd number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode , That is, the value of the K+1 to K+23 in the order from high to low in the first product result is determined as the operation of the floating-point number under the square root of the calculation or the reciprocal root of the calculation The value of the mantissa data segment of the result.
  • the value of the exponent data segment of the floating-point number is an even number
  • the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained.
  • the value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the second preset value is, for example, After obtaining the second product result, determine the number of digits of the first first preset value (for example, 1) in the order from high to low in the second product result.
  • This digit is called, for example, the Pth digit, and the second product is obtained
  • the value from the P+1 digit to the P+23 digit in the order from high to low in the result, and the value from the P+1 digit to the P+23 digit is determined as the floating point number in the calculation. Or calculate the value of the mantissa data segment of the operation result under the reciprocal root of the square.
  • the calculation mode is to calculate the reciprocal root. If the value of the exponent data segment of the floating-point number is an even number, the value of the preset digits is used as the mantissa data segment of the operation result of the floating-point number in the calculation mode Numerical value. If the value of the exponent data segment is an odd number, the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after a preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the value of the symbol data segment of the floating-point number is acquired at the storage address of the symbol data segment, and the value of the symbol data segment is obtained according to the symbol data segment.
  • the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and the address of the symbol data segment corresponding to the operation result of the floating-point number in the calculation mode is stored.
  • the value of the symbol data segment is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
  • the third preset value (for example, 0) is used as the value of the symbol data segment of the calculation result of the floating-point number in the calculation mode.
  • the exponent data segment in the floating-point number after obtaining the processing instruction of the floating-point number, read the value of the exponent data segment at the storage address of the exponent data segment; according to the exponent data The value of the segment, the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and the address of the exponent data segment corresponding to the operation result of the floating-point number in the calculation mode is stored.
  • the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained according to the value of the mantissa data segment and the value of the exponent data segment.
  • the value of the mantissa data segment is the third preset value
  • the value of 254-E i is used as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode; If the value of the mantissa data segment is not the third preset value, the value of 253-E i is used as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode.
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
  • the calculation mode includes calculating a square root, and if the value of the exponent data segment is an odd number, then Determined as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode; if the value of the exponent data segment is an even number, then The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode.
  • the calculation mode includes calculating the reciprocal root, and if the value of the exponent data segment is an odd number and the value of the mantissa data segment is not equal to a third preset value, then Determine the value of the exponent data segment as the result of the calculation of the floating-point number in the calculation mode; if the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then Determined as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode; if the value of the exponent data segment is an even number, then The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode.
  • E i is the value of the exponent data segment before the calculation.
  • the following describes the calculation of the reciprocal of floating-point numbers, the calculation of the square root, and the calculation of the reciprocal root of a floating-point number with the hardware architecture shown in Figure 5.
  • the reciprocal of the square root calculation, or the reciprocal square root is calculated for each symbol data segment S i, the index data segment E i, the mantissa data segment is calculated as M i, symbol data segment obtained after calculation is S 0,
  • the exponent data segment is E 0
  • the mantissa data segment is M 0 .
  • a n includes a total of 9 bits in the mantissa data segment of the floating-point number and m0-m8, and t n is a total of 14 bits in the mantissa data segment of the floating-point number.
  • the first arithmetic formula above is The above-mentioned addition operation formula is a n +(-1)t n .
  • a n may be expressed as: And k is an integer. According to the different values of k, calculate Thereby, a preset value table corresponding to the calculated reciprocal is obtained in advance and stored, where k is determined by m0 to m8.
  • the selector 1 calculates the reciprocal according to the selected calculation mode, selects E i to assign the coefficient -1, and outputs -E i to the adder 1 .
  • the selector 2 calculates the reciprocal according to the selected calculation mode, and determines the selector 3 corresponding to the calculated reciprocal from the selector 3, the selector 4, and the selector 5.
  • the selector 7 calculates the reciprocal according to the selected calculation mode, selects -t n , assigns a coefficient of -1 to the lower sub-data segment (t n ) of the mantissa data segment in the floating-point number, and outputs it to the adder 2, and the floating-point number
  • the high-order sub-data segment (a n ) of the mantissa data segment is input to the adder 2, and the adder 2 outputs (a n -t n ) to the multiplier 1.
  • Multiplier 1 will (a n -t n ) and Multiply to get The product of the value of and the value of (a n -t n ).
  • the product is 48 bits, for example. Determine the position of the first 1 in the product of 48 bits. This bit is the hidden bit of M 0. The bit starts from the high bit to the low bit and takes 23 bits in order, that is, 24 bits are obtained, and the 24 bits are stored in register 2.
  • the selector 8 calculates the reciprocal according to the selected calculation mode, obtains the 24-bit value from the register 2 and outputs it to obtain M 0 .
  • the E 0 stored in the register 1 is obtained and output.
  • this embodiment stores The reciprocal of the floating-point number is obtained by looking up the table and simple addition and multiplication operations in the preset data table of the operation result. Since this embodiment only stores the operation result of the upper sub-data section in the mantissa data section, the pre-set data table is reduced The storage capacity reduces the hardware cost and also improves the computing efficiency.
  • E i is odd, then If E i is even, then here It can be represented by 24'hB504F3.
  • a n includes a total of 9 bits in the mantissa data segment of the floating-point number and m0-m8, and t n is a total of 14 bits in the mantissa data segment of the floating-point number.
  • a n may be expressed as: And k is an integer. According to the different values of k, calculate Thereby, a preset numerical table corresponding to the square root of the calculation is obtained in advance and stored, where k is determined by m0 to m8.
  • the selector 1 calculates the square root according to the selected calculation mode, selects E i to assign a coefficient of 1, and outputs E i to the adder 1 .
  • the selector 2 is the calculation root based on the selected calculation mode, and the selector 4 corresponding to the calculation root is determined from the selector 3, the selector 4, and the selector 5.
  • the selector 7 calculates the square root according to the selected calculation mode, selects t n ⁇ 1, and assigns the low-order sub-data segment (t n ) of the mantissa data segment in the floating-point number And output to adder 2.
  • the high-order sub-data segment (a n ) of the mantissa data segment in the floating-point number is input to adder 2, and adder 2 outputs Give the multiplier 1.
  • the selector 6 calculates the square root according to the selected calculation mode, and selects E′ i >>1 to assign coefficients to E′ i obtain And output to register 1.
  • Multiplier 1 will versus Multiply to get And the value of The product of the value of, the product is 48bit, for example, determine the position of the first 1 in the product of 48bit, and take 23bit from the next bit of the bit from high to low, that is, 24bit is obtained, and the 24bit Store in register 2 and output the 24 bits to multiplier 2.
  • this embodiment stores The pre-set data table of the calculation result of the calculation result is obtained by looking up the table and simple addition and multiplication operations to obtain the root of the floating-point number. Since this embodiment only stores the calculation result of the upper sub-data section in the mantissa data section, the preset data table is reduced The storage capacity reduces the hardware cost and also improves the computing efficiency.
  • E i is odd, then If E i is even, then here It can be represented by 24'hB504F3.
  • a n includes a total of 9 bits in the mantissa data segment of the floating-point number and m0-m8, and t n is a total of 14 bits in the mantissa data segment of the floating-point number.
  • n may be expressed as: And k is an integer.
  • the above-mentioned first calculation formula can be set as The above first calculation formula can be set as The above addition formula is According to the different values of k, calculate Thereby, a preset numerical table corresponding to the reciprocal root of the calculation is obtained in advance and stored, where k is determined by m0 to m8.
  • the selector 1 calculates the reciprocal root according to the selected calculation mode, chooses to assign a coefficient of -1 to E i , and sends it to the adder 1 Output -E i .
  • the selector 2 calculates the reciprocal root of the calculation according to the selected calculation mode, and determines the selector 5 corresponding to the reciprocal root of the calculation from the selector 3, the selector 4, and the selector 5.
  • the selector 7 calculates the reciprocal square root according to the selected calculation mode, and selects -(t n ⁇ 1) to assign the lower sub-data segment (t n ) of the mantissa data segment in the floating-point number And output to adder 2.
  • the high-order sub-data segment (a n ) of the mantissa data segment in the floating-point number is input to adder 2, and adder 2 outputs Give the multiplier 1.
  • the selector 6 calculates the square root according to the selected calculation mode, and selects E′ i >>1 to assign coefficients to E′ i obtain And output to register 1.
  • Multiplier 1 will versus Multiply to get And the value of The product of the value of, the product is 48bit, for example, determine the position of the first 1 in the product of 48bit, and take 23bit from the next bit of the bit from high to low, that is, 24bit is obtained, and the 24bit Store in register 2 and output the 24 bits to multiplier 2.
  • Calculating S 0 in the third stage and temporarily storing E 0 in the register can ensure that the timing of S 0 , E 0 , and M 0 in the operation result is synchronized.
  • the first calculation formula in this implementation is The hardware of the third stage can be made the same as the hardware of the third stage when calculating the prescription, which saves the hardware cost.
  • the above-mentioned first calculation formula can be set as The above addition formula is According to the different values of k, calculate Thereby, a preset numerical table corresponding to the reciprocal root of the calculation is obtained in advance and stored, where k is determined by m0 to m8.
  • k is determined by m0 to m8.
  • the corresponding preset value table of the corresponding relationship to obtain the corresponding The value of and is obtained by the above addition operation unit The value of will be obtained through the first multiplier And the value of The product of the values, the product is 48bit.
  • E i is an odd number, take the position of the first 1 in the product obtained by the first multiplier and take 24 bits in the order of MSB from high to low, and then multiply by 2 through the second multiplier to obtain a 48-bit product. And determine the position of the first 1 in the product obtained by the second multiplier. This bit is used as the hidden bit of M 0 , and 23 bits are taken as M 0 in the order from the next bit to the low bit. If E i is an even number, the position of the first 1 in the product obtained by the first multiplier is taken from high to low in order of 24 bits, and then through the third multiplier and Multiply to obtain a 48-bit product, and determine the position of the first 1 in the product obtained by the third multiplier. This bit is used as the hidden bit of M 0 , starting from the next bit in the order from high to low Take 23bit as M 0 .
  • the first preset value table corresponds to E i as an even number.
  • the above-mentioned first calculation formula corresponding to the first preset value table can be set as The second preset value table corresponding to E i is odd, then the above-mentioned first calculation formula corresponding to the second preset value table can be set as The above addition formula is According to the different values of k, calculate In this way, the first preset value table corresponding to the reciprocal root of the calculation is obtained in advance and stored.
  • a second preset value table corresponding to the reciprocal root of the calculation is obtained in advance and stored, where k is determined by m0 to m8.
  • E i is an even number
  • the first preset value table of the corresponding relationship to obtain the corresponding The value of and is obtained by the above addition operation unit The value of will be obtained through the multiplier
  • the value of The product of the value of, the product is 48bit, and the position of the first 1 in the product of the 48bit is determined. This bit is used as the implicit bit of M 0 , and 23bit is taken from the next bit to the low bit in order from the next bit.
  • this embodiment stores and The preset data table of the related operation result is obtained by looking up the table and simple addition and multiplication operations to obtain the reciprocal root of the floating-point number. Since this embodiment only stores the operation result of the upper sub-data segment in the mantissa data segment, the preset value is reduced. The storage capacity of the data table reduces the hardware cost and also improves the computing efficiency.
  • the accuracy of calculating floating-point numbers in each calculation mode can be determined according to the number of bits of the remainder of Taylor expansion, and the remainder can be represented by t n.
  • the number of bits of the remainder determining the number of bits of the mantissa section data obtained by dividing a n t n and the number of bits. The more the number of bits obtained by dividing a n, the less the number of bits corresponding to t n, t and thus the number of bits n corresponding to the remainder of the fewer.
  • a number of bits by dividing the adjusted and a n t n the result may be adjusted precision floating-point arithmetic.
  • the more bits a n, a n corresponding greater range of possible values e.g., number of bits. 9 is a n, a n is in the range [0, 512)
  • the corresponding a n The storage capacity of the preset data table will increase, and the data quantity of the look-up table will increase. Therefore, in some embodiments, the number of bits can be appropriately adjusted with a n t n bits by, sacrifice some amount of computation to improve accuracy.
  • the floating-point number processing device 600 of this embodiment may include: a processor 601, an addition unit 602, and a first multiplier 603 , The first storage device 604 and the second storage device 605.
  • the first storage device 604 and the second storage device 605 may be the same storage device or different storage devices.
  • the floating-point number processing device 600 may further include a second multiplier 606.
  • the first storage device 604 is configured to store floating-point numbers and calculation results of floating-point numbers in calculation mode
  • the second storage device 605 is configured to store preset value tables corresponding to different calculation modes respectively;
  • the processor 601 is configured to:
  • the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
  • At the storage address of the mantissa data segment read the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment from the first storage device 604;
  • the first value is obtained by looking up the preset value table corresponding to the calculation mode stored in the second storage device 605, and the preset value table includes the high-order sub-data segment The corresponding relationship between the value of and the result calculated by the first calculation formula;
  • the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 604 corresponding to the The address of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
  • the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
  • the addition unit 602 includes a selector 6021 and an adder 6022, and the processor 601 is specifically configured to:
  • the numerical value of the high-order sub-data segment and the third value are input to the adder 6022 to obtain the second value.
  • the sum of the number of bits in the upper sub-data segment and the number of lower sub-data bits is equal to the number of bits in the mantissa data segment.
  • the number of bits in the upper sub-data segment and the number of bits in the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion.
  • the calculation mode includes calculating the reciprocal, calculating the square root, and calculating the reciprocal square root.
  • the first calculation formula is The addition operation formula is a+(-1)t;
  • the first calculation formula is The addition operation formula
  • the first calculation formula is The addition operation formula
  • a is the value of the upper sub-data segment
  • t is the value of the lower sub-data segment.
  • the processor 601 is specifically configured to:
  • the preset number of bits is the number of bits of the mantissa data segment.
  • the processor 601 is specifically configured to:
  • the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the floating point number further includes: an exponent data segment; and the processor 601 is specifically configured to:
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the calculation of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the preset number of bits The value of the mantissa data segment of the result.
  • the calculation mode includes calculating a square root
  • the processor 601 is specifically configured to:
  • the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
  • the value of the preset number of digits and the second preset value are input to the second multiplier 606 to obtain the second multiplication result, and the second multiplication result is obtained.
  • the value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the calculation mode includes calculating the reciprocal root
  • the processor 601 is specifically configured to:
  • the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
  • the value of the preset number of bits and the second preset value are input to the second multiplier 606 to obtain a second multiplication result, and the second multiplication result is obtained.
  • the value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the floating-point number includes a symbol data segment; the processor 601 is further configured to:
  • the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 604 corresponding to the floating-point number in the calculation mode
  • the symbol data segment address of the operation result below.
  • the processor 601 is specifically configured to:
  • calculation mode includes a reciprocal calculation, use the value of the symbol data segment as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode;
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the third preset value is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
  • the floating point number includes an exponent data segment; the processor 601 is further configured to:
  • At the storage address of the index data segment read the value of the index data segment from the first storage device 604;
  • the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 604 corresponding to the floating-point number in the calculation mode The address of the exponent data segment of the operation result under.
  • the processor 601 is specifically configured to:
  • calculation mode includes the reciprocal calculation, obtain the value of the exponent data segment of the operation result of the floating-point number in the calculation mode according to the value of the mantissa data segment and the value of the exponent data segment;
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
  • the calculation mode includes calculating the reciprocal
  • the processor 601 is specifically configured to:
  • the value of the mantissa data segment is the third preset value, use the value of 254-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
  • E i is the value of the exponent data segment before calculation.
  • the calculation mode includes calculating a square root
  • the processor 601 is specifically configured to:
  • E i is the value of the exponent data segment before calculation.
  • the calculation mode includes calculating the reciprocal root
  • the processor 601 is specifically configured to:
  • the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
  • E i is the value of the exponent data segment before calculation.
  • the floating-point number processing device 600 of this embodiment may further include: a memory (not shown in the figure) for storing program codes.
  • the memory is used for storing program codes.
  • the floating-point number The processing device 600 can implement the above-mentioned technical solutions.
  • the floating-point number processing device of this embodiment can be used to implement the technical solutions of FIG. 2 and the corresponding method embodiment, and its implementation principles and technical effects are similar, and will not be repeated here.
  • FIG. 7 is a schematic structural diagram of a movable platform provided by an embodiment of the application.
  • the movable platform 700 of this embodiment may include: a processor 701, an addition unit 702, a first multiplier 703, and a first multiplier 703.
  • the first storage device 704 and the second storage device 705 may be the same storage device or different storage devices.
  • the movable platform 700 may further include a second multiplier 706.
  • the first storage device 704 is configured to store floating-point numbers and calculation results of floating-point numbers in calculation mode
  • the second storage device 705 is configured to store preset value tables corresponding to different calculation modes, respectively;
  • the processor 701 is configured to:
  • the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
  • At the storage address of the mantissa data segment read the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment from the first storage device 704, respectively;
  • the first value is obtained by looking up a preset value table corresponding to the calculation mode stored in the second storage device 705, and the preset value table includes the high-order sub-data segment The corresponding relationship between the value of and the result calculated by the first calculation formula;
  • the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 704.
  • the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
  • the addition unit 702 includes a selector 7021 and an adder 7022, and the processor 701 is specifically configured to:
  • the numerical value of the high-order sub-data segment and the third value are input to the adder 7022 to obtain the second value.
  • the sum of the number of bits in the upper sub-data segment and the number of lower sub-data bits is equal to the number of bits in the mantissa data segment.
  • the number of bits in the upper sub-data segment and the number of bits in the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion.
  • the calculation mode includes calculating the reciprocal, calculating the square root, and calculating the reciprocal square root.
  • the first calculation formula is The addition operation formula is a+(-1)t;
  • the first calculation formula is The addition operation formula
  • the first calculation formula is The addition operation formula
  • a is the value of the upper sub-data segment
  • t is the value of the lower sub-data segment.
  • the processor 701 is specifically configured to:
  • the preset number of bits is the number of bits of the mantissa data segment.
  • the processor 701 is specifically configured to:
  • the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the floating point number further includes: an exponent data segment; and the processor 701 is specifically configured to:
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the calculation of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the preset number of bits The value of the mantissa data segment of the result.
  • the calculation mode includes calculating a square root
  • the processor 701 is specifically configured to:
  • the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating point number in the calculation mode;
  • the value of the preset number of digits and the second preset value are input to the second multiplier 706 to obtain the second multiplication result, and the second multiplication result is obtained.
  • the value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the calculation mode includes calculating the reciprocal root
  • the processor 701 is specifically configured to:
  • the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
  • the value of the preset number of bits and the second preset value are input to the second multiplier 706 to obtain a second multiplication result, and the second multiplication result is obtained.
  • the value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  • the floating-point number includes a symbol data segment; the processor 701 is further configured to:
  • the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 704 corresponding to the floating-point number in the calculation mode
  • the symbol data segment address of the operation result below.
  • the processor 701 is specifically configured to:
  • calculation mode includes a reciprocal calculation, use the value of the symbol data segment as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode;
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the third preset value is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
  • the floating point number includes an exponent data segment; the processor 701 is further configured to:
  • the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 704 corresponding to the floating-point number in the calculation mode The address of the exponent data segment of the operation result under.
  • the processor 701 is specifically configured to:
  • calculation mode includes the reciprocal calculation, obtain the value of the exponent data segment of the operation result of the floating-point number in the calculation mode according to the value of the mantissa data segment and the value of the exponent data segment;
  • the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square
  • the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
  • the calculation mode includes calculating the reciprocal
  • the processor 701 is specifically configured to:
  • the value of the mantissa data segment is the third preset value, use the value of 254-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
  • E i is the value of the exponent data segment before calculation.
  • the calculation mode includes calculating a square root
  • the processor 701 is specifically configured to:
  • E i is the value of the exponent data segment before calculation.
  • the calculation mode includes calculating the reciprocal root
  • the processor 701 is specifically configured to:
  • the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
  • E i is the value of the exponent data segment before calculation.
  • the movable platform 700 of this embodiment may further include: a memory (not shown in the figure) for storing program codes, the memory is used for storing program codes, and when the program codes are executed, the movable platform 700 can implement the above-mentioned technical solutions.
  • the movable platform of this embodiment can be used to implement the technical solutions of FIG. 2 and the corresponding method embodiments, and its implementation principles and technical effects are similar, and will not be repeated here.
  • FIG. 8 is a schematic structural diagram of a movable platform provided by another embodiment of this application.
  • the movable platform 800 of this embodiment may include: a movable platform body 801 and a floating-point number processing device 802.
  • the floating-point number processing device 802 is installed on the movable platform body 801.
  • the floating-point number processing device 802 may be a device independent of the movable platform body 801.
  • the floating-point number processing device 802 can adopt the structure of the device embodiment shown in FIG. 6, and it can correspondingly execute the technical solutions of the embodiment of FIG. 2 and its corresponding method. Its implementation principles and technical effects are similar, and will not be repeated here. .
  • a person of ordinary skill in the art can understand that all or part of the steps in the above method embodiments can be implemented by a program instructing relevant hardware.
  • the foregoing program can be stored in a computer readable storage medium. When the program is executed, it is executed. Including the steps of the foregoing method embodiment; and the foregoing storage medium includes: read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disks or optical disks, etc., which can store program codes Medium.

Abstract

A method for processing a floating point number, a device, and a mobile platform. The method comprises: acquiring a processing instruction of a floating point number (S201); at a storage address of a mantissa data segment, reading a high-bit sub-data segment and a low-bit sub-data segment of the mantissa data segment, respectively (S202); according to the numerical value of the high-bit sub-data segment, searching in a preset numerical value table of a corresponding calculation mode for and obtaining a first value (S203); inputting the numerical value of the high-bit sub-data segment and the numerical value of the low-bit sub-data segment into an addition operation unit such that the addition operation unit executes an operation according to an addition operation formula of the corresponding calculation mode so as to obtain a second value (S204); inputting the first value and the second value into a first multiplier to obtain a first product result (S205); and according to the first product result, acquiring the numerical value of a mantissa data segment of an operation result of a floating point number in a calculation mode, and storing same at a mantissa data segment address of the operation result of the corresponding floating point number in the calculation mode (S206). Thus, operation efficiency is improved.

Description

浮点数处理方法、设备和可移动平台Floating point number processing method, equipment and movable platform 技术领域Technical field
本申请实施例涉及数据处理技术领域,尤其涉及一种浮点数处理方法、设备和可移动平台。The embodiments of the present application relate to the field of data processing technology, and in particular, to a floating-point number processing method, device, and movable platform.
背景技术Background technique
在计算机系统中,业界曾提出过多种实数的表达方式,比典型的有定点数,在定点数表达法中,其小数点固定地位于实数所有数字中间的位置。但定点数表达法中,固定的小数点位置决定了固定位数的整数部分和小数部分,不利于同时表达特别大的数或者特别小的数。因此,又提出了浮点数表达法,其中,浮点数,是属于有理数中某特定子集的数的数字表示,在计算机中用以近似表示任意某个实数。浮点数计算是指浮点数参与的运算,这种运算通常伴随着近似或舍入。一般地,可以对浮点数进行加,减,乘,比较等较为简单的运算,在一些应用场景下,还需要浮点数做一些非线性运算,例如:计算倒数、计算开方以及计算开方倒数。但是由于非线性计算过程比较复杂,需占用较多的处理资源,降低了处理效率。In computer systems, the industry has proposed a variety of expressions for real numbers, which are more fixed-point numbers than typical ones. In fixed-point number expressions, the decimal point is fixedly located in the middle of all the real numbers. However, in the fixed-point number expression method, the fixed decimal point position determines the integer part and the decimal part of the fixed number of digits, which is not conducive to expressing very large numbers or very small numbers at the same time. Therefore, the floating-point number expression method was also proposed. Among them, floating-point number is a digital representation of a certain subset of rational numbers, which is used to approximate any real number in a computer. Floating-point calculations refer to operations involving floating-point numbers, which are usually accompanied by approximation or rounding. Generally, simpler operations such as addition, subtraction, multiplication, and comparison can be performed on floating-point numbers. In some application scenarios, floating-point numbers are also required to perform some non-linear operations, such as calculating the reciprocal, calculating the square root, and calculating the reciprocal square root. . However, because the nonlinear calculation process is more complicated, it takes up more processing resources, which reduces the processing efficiency.
发明内容Summary of the invention
本申请实施例提供一种浮点数处理方法、设备和可移动平台,提高了浮点数的运算效率,降低了硬件成本。The embodiments of the present application provide a floating-point number processing method, device, and a movable platform, which improve the operating efficiency of floating-point numbers and reduce hardware costs.
第一方面,本申请实施例提供一种浮点数处理方法,包括:In the first aspect, an embodiment of the present application provides a floating-point number processing method, including:
获取浮点数的处理指令,所述处理指令用于指示浮点数的计算模式,所述浮点数包括尾数数据段;Acquiring a processing instruction of a floating-point number, the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
在所述尾数数据段的存储地址,分别读取所述尾数数据段的高位子数据段和低位子数据段;At the storage address of the mantissa data section, respectively read the high-order sub-data section and the low-order sub-data section of the mantissa data section;
根据所述高位子数据段的数值,在对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;According to the value of the high-order sub-data segment, the first value is found in a preset value table corresponding to the calculation mode, and the preset value table includes the value of the high-order sub-data segment and calculated by a first calculation formula Correspondence of the results obtained;
将所述高位子数据段的数值和低位子数据段的数值输入加法运算单元,以使所述加法运算单元根据对应所述计算模式的加法运算公式执行运算,得到第二值;Input the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment into an addition unit, so that the addition unit performs an operation according to an addition formula corresponding to the calculation mode to obtain a second value;
将所述第一值和所述第二值输入第一乘法器,得到第一乘积结果;Input the first value and the second value to a first multiplier to obtain a first product result;
根据所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值并且存入对应所述浮点数在所述计算模式下的运算结果的尾数数据段地址;According to the first product result, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the address of the mantissa data segment corresponding to the operation result of the floating-point number in the calculation mode ;
其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。Wherein, the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
第二方面,本申请实施例提供一种浮点数处理设备,包括:处理器、加法运算单元、第一乘法器、第一存储装置和第二存储装置;In a second aspect, an embodiment of the present application provides a floating-point number processing device, including: a processor, an addition unit, a first multiplier, a first storage device, and a second storage device;
所述第一存储装置,用于存储浮点数以及浮点数在计算模式下的运算结果;The first storage device is used to store floating-point numbers and calculation results of floating-point numbers in calculation mode;
所述第二存储装置,用于存储不同计算模式分别对应的预设数值表;The second storage device is used to store preset value tables corresponding to different calculation modes respectively;
所述处理器,用于:The processor is used to:
获取浮点数的处理指令,所述处理指令用于指示浮点数的计算模式,所述浮点数包括尾数数据段;Acquiring a processing instruction of a floating-point number, the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
在所述尾数数据段的存储地址,从所述第一存储装置中分别读取所述尾数数据段的高位子数据段和低位子数据段;At the storage address of the mantissa data segment, respectively reading the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment from the first storage device;
根据所述高位子数据段的数值,在所述第二存储装置存储的对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;According to the value of the high-order sub-data segment, the first value is obtained by looking up the preset value table corresponding to the calculation mode stored in the second storage device, and the preset value table includes the value of the high-order sub-data segment. Correspondence between the value and the result calculated by the first calculation formula;
将所述高位子数据段的数值和低位子数据段的数值输入所述加法运算单元,以使所述加法运算单元根据对应所述计算模式的加法运算公式执行运算,得到第二值;Input the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment into the addition unit, so that the addition unit performs an operation according to the addition formula corresponding to the calculation mode to obtain a second value;
将所述第一值和所述加法运算单元计算得到的所述第二值输入第一乘法器,得到第一乘积结果;Input the first value and the second value calculated by the addition unit into a first multiplier to obtain a first product result;
根据所述第一乘法器得到的所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值并且存入所述第二存储装置中对应所述浮点数在所述计算模式下的运算结果的尾数数据段地址;According to the first product result obtained by the first multiplier, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the second storage device corresponding to the float The address of the mantissa data segment of the operation result of the point in the calculation mode;
其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。Wherein, the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
第三方面,本申请实施例提供一种可移动平台,包括:可移动平台本体以及如第一方面本申请实施例所述的浮点数处理设备,其中,所述浮点数处理设备安装于所述可移动平台本体上。In a third aspect, an embodiment of the present application provides a movable platform, including: a movable platform body and the floating-point number processing device according to the embodiment of the present application in the first aspect, wherein the floating-point number processing device is installed in the On the movable platform body.
第四方面,本申请实施例提供一种可读存储介质,所述可读存储介质上存储有计算机程序;所述计算机程序在被执行时,实现如第一方面本申请实施例所述的浮点数处理方法。In a fourth aspect, an embodiment of the present application provides a readable storage medium with a computer program stored on the readable storage medium; when the computer program is executed, it implements the float described in the embodiment of the present application in the first aspect. Point processing method.
第五方面,本申请实施例提供一种程序产品,所述程序产品包括计算机程序,所述计算机程序存储在可读存储介质中,可移动平台的至少一个处理器可以从所述可读存储介质读取所述计算机程序,所述至少一个处理器执行所述计算机程序使得可移动平台实施如第一方面本申请实施例所述的浮点数处理方法。In a fifth aspect, an embodiment of the present application provides a program product, the program product includes a computer program, the computer program is stored in a readable storage medium, and at least one processor of a removable platform can download from the readable storage medium The computer program is read, and the at least one processor executes the computer program to enable the mobile platform to implement the floating-point number processing method described in the embodiment of the present application in the first aspect.
本申请实施例提供的种浮点数处理方法、设备和可移动平台,通过根据浮点数的尾数数据段中高位子数据段的数值,在对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;以及将所述高位子数据段的数值和尾数数据段中低位子数据段的数值输入加法运算单元,以使所述加法运算单元根据对应所述计算模式的加法运算公式执行运算,得到第二值;然后将所述第一值和所述第二值输入第一乘法器,得到第一乘积结果;再根据所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。本实施例预先存储的是不同种类的计算模式对应的尾数数据段中高位子数据段的预设数值表,而不是对应整个尾数数据段的预设数值表,降低了预设数值表的存储量,提高了查预设数值表的速度。而且不同种类的计算模式,复用了加法运算单元和乘法器,进行的是简单线性运算即可获得多种类非线性复杂运算的结果,降低了硬件成本,提高了运算效率。According to the floating-point number processing method, device and movable platform provided by the embodiments of the present application, the first value is obtained by looking up the value of the upper sub-data segment in the mantissa data segment of the floating-point number in the preset value table corresponding to the calculation mode The preset value table includes the corresponding relationship between the value of the high-order sub-data segment and the result calculated by the first calculation formula; and the value of the high-order sub-data segment and the value of the low-order sub-data segment in the mantissa data segment The numerical value is input to the addition unit, so that the addition unit performs an operation according to the addition formula corresponding to the calculation mode to obtain a second value; then the first value and the second value are input to the first multiplier, Obtain the first product result; and then, according to the first product result, obtain the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode; wherein the product of the first operation formula and the addition operation formula , Constitute the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode. In this embodiment, the preset value table of the higher sub-data segment in the mantissa data segment corresponding to different types of calculation modes is pre-stored, instead of the preset value table corresponding to the entire mantissa data segment, which reduces the storage capacity of the preset value table. Improved the speed of checking the preset value table. In addition, different types of calculation modes reuse addition units and multipliers, and perform simple linear operations to obtain the results of various types of nonlinear complex operations, reduce hardware costs, and improve computing efficiency.
附图说明Description of the drawings
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly describe the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description These are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work.
图1是根据本申请的实施例的无人飞行系统的示意性架构图;Fig. 1 is a schematic architecture diagram of an unmanned aerial system according to an embodiment of the present application;
图2为本申请一实施例提供的浮点数处理方法的流程图;2 is a flowchart of a floating-point number processing method provided by an embodiment of the application;
图3为本申请一实施例提供的浮点数的一种格式示意图;FIG. 3 is a schematic diagram of a format of a floating point number provided by an embodiment of the application;
图4为本申请一实施例提供的浮点数的尾数数据段中高位子数据段和低位子数据段的一种示意图;4 is a schematic diagram of the high-order sub-data segment and the low-order sub-data segment in the mantissa data segment of a floating-point number provided by an embodiment of the application;
图5为本申请一实施例提供的硬件架构示意图;FIG. 5 is a schematic diagram of the hardware architecture provided by an embodiment of the application;
图6为本申请一实施例提供的浮点数处理设备的结构示意图;6 is a schematic structural diagram of a floating-point number processing device provided by an embodiment of the application;
图7为本申请一实施例提供的可移动平台的结构示意图;FIG. 7 is a schematic structural diagram of a movable platform provided by an embodiment of this application;
图8为本申请另一实施例提供的可移动平台的结构示意图。FIG. 8 is a schematic structural diagram of a movable platform provided by another embodiment of the application.
具体实施方式detailed description
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments It is a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by a person of ordinary skill in the art without creative work shall fall within the protection scope of this application.
本申请的实施例提供了浮点数处理方法、设备和可移动平台,其中,可移动平台可以是手持电话、手持云台、无人机、无人车、无人船、机器人或自动驾驶汽车等。以下对本申请可移动平台的描述使用无人机作为示例。对于本领域技术人员将会显而易见的是,可以不受限制地使用其他类型的无人机,本申请的实施例可以应用于各种类型的无人机。例如,无人机可以是小型或大型的无人机。在某些实施例中,无人机可以是旋翼无人机(rotorcraft),例如,由多个推动装置通过空气推动的多旋翼无人机,本申请的实施例并不限于此,无人机也可以是其它类型的无人机。The embodiments of the present application provide floating-point number processing methods, equipment, and mobile platforms, where the mobile platforms can be handheld phones, handheld PTZ, unmanned aerial vehicles, unmanned vehicles, unmanned ships, robots, or self-driving cars, etc. . The following description of the mobile platform of this application uses drones as an example. It will be obvious to those skilled in the art that other types of drones can be used without restriction, and the embodiments of the present application can be applied to various types of drones. For example, the drone can be a small or large drone. In some embodiments, the drone may be a rotorcraft, for example, a multi-rotor drone that is propelled by multiple propulsion devices through the air. The embodiments of the present application are not limited to this, and the drone It can also be other types of drones.
图1是根据本申请的实施例的无人飞行系统的示意性架构图。本实施例以旋翼无人机为例进行说明。Fig. 1 is a schematic architecture diagram of an unmanned aerial system according to an embodiment of the present application. In this embodiment, a rotary wing drone is taken as an example for description.
无人飞行系统100可以包括无人机110、显示设备130和遥控设备140。其中,无人机110可以包括动力系统150、飞行控制系统160、机架和承载在机架上的云台120。无人机110可以与遥控设备140和显示设备130进行无线通信。The unmanned aerial system 100 may include a drone 110, a display device 130, and a remote control device 140. Among them, the UAV 110 may include a power system 150, a flight control system 160, a frame, and a pan/tilt 120 carried on the frame. The drone 110 can wirelessly communicate with the remote control device 140 and the display device 130.
机架可以包括机身和脚架(也称为起落架)。机身可以包括中心架以及与中心架连接的一个或多个机臂,一个或多个机臂呈辐射状从中心架延伸出。脚架与机身连接,用于在无人机110着陆时起支撑作用。The frame may include a fuselage and a tripod (also called a landing gear). The fuselage may include a center frame and one or more arms connected to the center frame, and the one or more arms extend radially from the center frame. The tripod is connected with the fuselage, and is used for supporting the UAV 110 when it is landed.
动力系统150可以包括一个或多个电子调速器(简称为电调)151、一个或多个螺旋桨153以及与一个或多个螺旋桨153相对应的一个或多个电机152,其中电机152连接在电子调速器151与螺旋桨153之间,电机152和螺旋桨153设置在无人机110的机臂上;电子调速器151用于接收飞行控制系统160产生的驱动信号,并根据驱动信号提供驱动电流给电机152,以控制电机152的转速。电机152用于驱动螺旋桨旋转,从而为无人机110的飞行提供动力,该动力使得无人机110能够实现一个或多个自由度的运动。在某些实施例中,无人机110可以围绕一个或多个旋转轴旋转。例如,上述旋转轴可以包括横滚轴(Roll)、偏航轴(Yaw)和俯仰轴(pitch)。应理解,电机152可以是直流电机,也可以交流电机。另外,电机152可以是无刷电机,也可以是有刷电机。The power system 150 may include one or more electronic governors (referred to as ESCs) 151, one or more propellers 153, and one or more motors 152 corresponding to the one or more propellers 153, wherein the motors 152 are connected to Between the electronic governor 151 and the propeller 153, the motor 152 and the propeller 153 are arranged on the arm of the UAV 110; the electronic governor 151 is used to receive the driving signal generated by the flight control system 160 and provide driving according to the driving signal Current is supplied to the motor 152 to control the speed of the motor 152. The motor 152 is used to drive the propeller to rotate, thereby providing power for the flight of the drone 110, and the power enables the drone 110 to achieve one or more degrees of freedom of movement. In some embodiments, the drone 110 may rotate about one or more rotation axes. For example, the aforementioned rotation axis may include a roll axis (Roll), a yaw axis (Yaw), and a pitch axis (pitch). It should be understood that the motor 152 may be a DC motor or an AC motor. In addition, the motor 152 may be a brushless motor or a brushed motor.
飞行控制系统160可以包括飞行控制器161和传感系统162。传感系统162用于测量无人机的姿态信息,即无人机110在空间的位置信息和状态信息,例如,三维位置、三维角度、三维速度、三维加速度和三维角速度等。传感系统162例如可以包括陀螺仪、超声传感器、电子罗盘、惯性测量单元(Inertial Measurement Unit,IMU)、视觉传感器、全球导航卫星系统和气压计等传感器中的至少一种。例如,全球导航卫星系统可以是全球定位系统(Global Positioning System,GPS)。飞行控制器161用于控制无人机110的飞行,例如,可以根据传感系统162测量的姿态信息控制无人机110的飞行。应理解,飞行控制器161可以按照预先编好的程序指令对无人机110进行控制,也可以通过响应来自遥控设备140的一个或多个遥控信号对无人机110进行控制。The flight control system 160 may include a flight controller 161 and a sensing system 162. The sensing system 162 is used to measure the attitude information of the drone, that is, the position information and state information of the drone 110 in space, such as three-dimensional position, three-dimensional angle, three-dimensional velocity, three-dimensional acceleration, and three-dimensional angular velocity. The sensing system 162 may include, for example, at least one of sensors such as a gyroscope, an ultrasonic sensor, an electronic compass, an inertial measurement unit (IMU), a vision sensor, a global navigation satellite system, and a barometer. For example, the global navigation satellite system may be the Global Positioning System (GPS). The flight controller 161 is used to control the flight of the drone 110, for example, it can control the flight of the drone 110 according to the attitude information measured by the sensor system 162. It should be understood that the flight controller 161 can control the drone 110 according to pre-programmed program instructions, and can also control the drone 110 by responding to one or more remote control signals from the remote control device 140.
云台120可以包括电机122。云台用于携带拍摄装置123。飞行控制器 161可以通过电机122控制云台120的运动。可选地,作为另一实施例,云台120还可以包括控制器,用于通过控制电机122来控制云台120的运动。应理解,云台120可以独立于无人机110,也可以为无人机110的一部分。应理解,电机122可以是直流电机,也可以是交流电机。另外,电机122可以是无刷电机,也可以是有刷电机。还应理解,云台可以位于无人机的顶部,也可以位于无人机的底部。The pan/tilt head 120 may include a motor 122. The pan/tilt is used to carry the camera 123. The flight controller 161 can control the movement of the pan/tilt 120 through the motor 122. Optionally, as another embodiment, the pan/tilt head 120 may further include a controller for controlling the movement of the pan/tilt head 120 by controlling the motor 122. It should be understood that the pan-tilt 120 may be independent of the drone 110 or a part of the drone 110. It should be understood that the motor 122 may be a DC motor or an AC motor. In addition, the motor 122 may be a brushless motor or a brushed motor. It should also be understood that the pan-tilt can be located on the top of the drone, or on the bottom of the drone.
拍摄装置123例如可以是照相机或摄像机等用于捕获图像的设备,拍摄装置123可以与飞行控制器通信,并在飞行控制器的控制下进行拍摄。本实施例的拍摄装置123至少包括感光元件,该感光元件例如为互补金属氧化物半导体(Complementary Metal Oxide Semiconductor,CMOS)传感器或电荷耦合元件(Charge-coupled Device,CCD)传感器。可以理解,拍摄装置123也可直接固定于无人机110上,从而云台120可以省略。The photographing device 123 may be, for example, a device for capturing images, such as a camera or a video camera, and the photographing device 123 may communicate with the flight controller and take pictures under the control of the flight controller. The imaging device 123 of this embodiment at least includes a photosensitive element, and the photosensitive element is, for example, a Complementary Metal Oxide Semiconductor (CMOS) sensor or a Charge-coupled Device (CCD) sensor. It can be understood that the camera 123 can also be directly fixed to the drone 110, so the pan/tilt 120 can be omitted.
显示设备130位于无人飞行系统100的地面端,可以通过无线方式与无人机110进行通信,并且可以用于显示无人机110的姿态信息。另外,还可以在显示设备130上显示拍摄装置123拍摄的图像。应理解,显示设备130可以是独立的设备,也可以集成在遥控设备140中。The display device 130 is located on the ground end of the unmanned aerial system 100, can communicate with the drone 110 in a wireless manner, and can be used to display the attitude information of the drone 110. In addition, the image photographed by the photographing device 123 may also be displayed on the display device 130. It should be understood that the display device 130 may be an independent device or integrated in the remote control device 140.
遥控设备140位于无人飞行系统100的地面端,可以通过无线方式与无人机110进行通信,用于对无人机110进行远程操纵。The remote control device 140 is located on the ground end of the unmanned aerial system 100, and can communicate with the drone 110 in a wireless manner for remote control of the drone 110.
应理解,上述对于无人飞行系统各组成部分的命名仅是出于标识的目的,并不应理解为对本申请的实施例的限制。It should be understood that the aforementioned naming of the components of the unmanned aerial system is only for identification purposes, and should not be understood as a limitation to the embodiments of the present application.
其中,在对上述拍摄装置123拍摄的图像进行处理时,会涉及到对浮点数的处理,对浮点数的处理可以参见下述各实施例中的相关描述。需要说明的是,浮点数的处理不限于上述应用场景,也可以应用于有关传感器、图像传输、智能驾驶等领域,涉及浮点数的处理均可采用本申请实施例的方案。Wherein, when processing the image taken by the above-mentioned photographing device 123, the processing of floating-point numbers is involved, and the processing of floating-point numbers can refer to the relevant descriptions in the following embodiments. It should be noted that the processing of floating-point numbers is not limited to the above-mentioned application scenarios, and can also be applied to related fields such as sensors, image transmission, and intelligent driving. The processing of floating-point numbers can all adopt the solutions of the embodiments of the present application.
图2为本申请一实施例提供的浮点数处理方法的流程图,如图2所示,本实施例的方法可以包括:Fig. 2 is a flowchart of a floating-point number processing method provided by an embodiment of the application. As shown in Fig. 2, the method of this embodiment may include:
S201、获取浮点数的处理指令。S201. Obtain a processing instruction of a floating-point number.
本实施例中,浮点数包括尾数数据段,浮点数还可以包括符号数据段和指数数据段,如图3所示,其中,符号数据段(s)是1比特(bit)的符号位(sign),指数数据段(Exponent)是8bit的指数位(e),尾数数据段(Mantissa) 是23bit的小数位(m),需要说明的是,尾数数据段省去了隐含位1,即Mantissa实际表示的是1.m。因此,规格化的浮点数表示的值为:In this embodiment, the floating-point number includes a mantissa data segment, and the floating-point number can also include a sign data segment and an exponent data segment, as shown in FIG. 3, where the sign data segment (s) is a 1-bit (sign) bit. ), the exponent data segment (Exponent) is an 8-bit exponent bit (e), and the mantissa data segment (Mantissa) is a 23-bit decimal place (m). It should be noted that the mantissa data segment omits the implicit bit 1, namely Mantissa The actual representation is 1.m. Therefore, the value represented by the normalized floating point number is:
Val=(-1) sign*2 e-bias*(1.m) Val=(-1) sign *2 e-bias *(1.m)
而且bias的值为127。And the value of bias is 127.
本实施例中,获取浮点数的处理指令,该处理指令用于指示浮点数的计算模式,其中,计算模式例如可以是:计算倒数(例如计算
Figure PCTCN2019108872-appb-000001
),或者,计算开方(例如计算
Figure PCTCN2019108872-appb-000002
),或者,计算开方倒数(例如计算
Figure PCTCN2019108872-appb-000003
),本实施例并不限于此。
In this embodiment, a processing instruction for a floating-point number is acquired. The processing instruction is used to indicate a calculation mode of the floating-point number.
Figure PCTCN2019108872-appb-000001
), or, calculate the square root (e.g. calculate
Figure PCTCN2019108872-appb-000002
), or to calculate the reciprocal of the root (for example, to calculate
Figure PCTCN2019108872-appb-000003
), this embodiment is not limited to this.
其中,浮点数的处理指令可以是在对数据进行处理的过程中确定的指令,若当需要对浮点数进行倒数运算时,则确定获取到用于指示浮点数的计算模式为计算倒数的处理指令;若当需要对浮点数进行开方运算时,则确定获取到用于指示浮点数的计算模式为计算开方的处理指令;若当需要对浮点数进行开方倒数运算时,则确定获取到用于指示浮点数的计算模式为计算开方倒数的处理指令。Among them, the floating-point number processing instruction can be an instruction determined in the process of processing the data. If the floating-point number needs to be reciprocated, it is determined that the obtained calculation mode for indicating the floating-point number is the processing instruction for calculating the reciprocal. ; If it is necessary to perform square root operation on a floating-point number, it is determined that the processing instruction used to indicate that the calculation mode of the floating-point number is the calculation square root is obtained; if it is necessary to perform the reciprocal square root operation on the floating-point number, it is determined to obtain The calculation mode used to indicate the floating-point number is a processing instruction for calculating the reciprocal of the root.
S202、在尾数数据段的存储地址,分别读取尾数数据段的高位子数据段和低位子数据段。S202: At the storage address of the mantissa data section, read the high-order sub-data section and the low-order sub-data section of the mantissa data section respectively.
本实施例中,在获取到浮点数的处理指令后,确定该浮点数的尾数数据段的存储地址,然后在该尾数数据段的存储地址,读取尾数数据段,其中,本实施例的读取方式为:分别读取尾数数据段的高位子数据段和低位子数据段。In this embodiment, after the processing instruction of the floating-point number is obtained, the storage address of the mantissa data segment of the floating-point number is determined, and then the mantissa data segment is read at the storage address of the mantissa data segment, where the reading of this embodiment The method is to read the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment respectively.
S203、根据高位子数据段的数值,在对应计算模式的预设数值表中查找得到第一值。S203: According to the value of the high-order sub-data segment, the first value is obtained by searching in the preset value table of the corresponding calculation mode.
本实施例中,预先存储有对应不同计算模式的预设数值表,即不同的计算模式所对应的预设数值表可能不同。以各计算模式包括:计算倒数、计算开方、计算开方倒数为例,则本实施例预先存储有三个预设数值表,分别为:对应计算倒数的预设数值表、对应计算开方的预设数值表、对应计算开方倒数的预设数值表。In this embodiment, preset value tables corresponding to different calculation modes are pre-stored, that is, the preset value tables corresponding to different calculation modes may be different. Taking each calculation mode including: calculating the reciprocal, calculating the square root, and calculating the reciprocal square root as an example, this embodiment has three preset value tables pre-stored, namely: the preset value table corresponding to the reciprocal calculation, and the one corresponding to the calculation root. Preset value table, corresponding to the preset value table for calculating the reciprocal root.
并且,预设数值表中包括各浮点数的高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系。其中,针对不同的计算模式,第一运算公式可能不同。本实施例中,在读取到高位子数据段之后,根据该高位子数 据段的数值,从对应该计算模式的预设数值表中查找得到第一值,该第一值是预先该高位子数据段的数值经过第一运算公式计算得到的结果。In addition, the preset value table includes the corresponding relationship between the value of the upper sub-data segment of each floating-point number and the result calculated by the first calculation formula. Among them, for different calculation modes, the first calculation formula may be different. In this embodiment, after the high-order sub-data segment is read, the first value is obtained from the preset value table corresponding to the calculation mode according to the value of the high-order sub-data segment. The value of the data segment is calculated by the first calculation formula.
S204、将高位子数据段的数值和低位子数据段的数值输入加法运算单元,使加法运算单元根据对应所算模式的加法运算公式执行运算,得到第二值。S204. Input the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment into the addition unit, so that the addition unit performs the operation according to the addition operation formula corresponding to the calculated mode to obtain the second value.
本实施例中,在读取高位子数据段的数值以及低位子数据段的数值之后,将高位子数据段的数值和低位子数据段的数据输入加法运算单元,然后加法运算单元根据对应该计算模式的加法运算公式,对高位子数据段的数值和低位子数据段的数据执行运算,得到第二值。其中,针对不同的计算模式,对应的加法运算公式可能不同。In this embodiment, after reading the value of the high-order sub-data segment and the value of the low-order sub-data segment, the value of the high-order sub-data segment and the data of the low-order sub-data segment are input to the addition unit, and then the addition unit calculates according to the corresponding The addition formula of the pattern is to perform operations on the value of the upper sub-data segment and the data of the lower sub-data segment to obtain the second value. Among them, for different calculation modes, the corresponding addition operation formula may be different.
其中,所述第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。Wherein, the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
需要说明的是,S203和S204的执行顺序不分先后。It should be noted that the execution order of S203 and S204 is in no particular order.
S205、将第一值和第二值输入第一乘法器,得到第一乘积结果。S205. Input the first value and the second value to the first multiplier to obtain a first product result.
本实施例,在计算得到第一值和第二值之后,将第一值和第二值输入乘法器,该乘法器称为第一乘法器,第一乘法器将第一值与第二值相乘,得到一乘积结果,该乘积结果称为第一乘积结果。In this embodiment, after the first value and the second value are calculated, the first value and the second value are input to the multiplier. The multiplier is called the first multiplier. The first multiplier combines the first value with the second value. Multiply to obtain a product result, which is called the first product result.
S206、根据第一乘积结果,获得浮点数在计算模式下的运算结果的尾数数据段的数值并且存入对应浮点数在计算模式下的运算结果的尾数数据段地址。S206: Obtain the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the first product result, and store the mantissa data segment address of the operation result of the corresponding floating-point number in the calculation mode.
本实施例中,根据该第一乘积结果,获得该浮点数在该计算模式下的运算结果的尾数数据段的数值,并将浮点数在该计算模式下的运算结果的尾数数据段的数值存入对应该浮点数在该计算模式下的运算结果的尾数数据段地址。In this embodiment, according to the first product result, the value of the mantissa data section of the operation result of the floating-point number in the calculation mode is obtained, and the value of the mantissa data section of the operation result of the floating-point number in the calculation mode is stored. Enter the address of the mantissa data segment corresponding to the operation result of the floating-point number in this calculation mode.
本实施例中,通过根据浮点数的尾数数据段中高位子数据段的数值,在对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;以及将所述高位子数据段的数值和尾数数据段中低位子数据段的数值输入加法运算单元,以使所述加法运算单元根据对应所述计算模式的加法运算公式执行运算,得到第二值;然后将所述第一值和所述第二值输入第一乘法器,得到第一乘积结果;再根据所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部 分。本实施例预先存储的是不同种类的计算模式对应的尾数数据段中高位子数据段的预设数值表,而不是对应整个尾数数据段的预设数值表,降低了预设数值表的存储量,提高了查预设数值表的速度。而且不同种类的计算模式,复用了加法运算单元和乘法器,进行的是简单线性运算即可获得多种类非线性复杂运算的结果,降低了硬件成本,提高了运算效率。In this embodiment, the first value is found in the preset value table corresponding to the calculation mode according to the value of the upper sub-data segment in the mantissa data segment of the floating-point number, and the preset value table includes the upper sub-data. The corresponding relationship between the value of the segment and the result calculated by the first operation formula; and input the value of the high-order sub-data segment and the value of the low-order sub-data segment in the mantissa data segment into the addition unit, so that the addition unit Perform operations according to the addition formula corresponding to the calculation mode to obtain the second value; then input the first value and the second value into the first multiplier to obtain the first product result; and then according to the first product As a result, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained; wherein, the product of the first operation formula and the addition operation formula constitutes Taylor of the function expression corresponding to the calculation mode The polynomial part of the expansion. In this embodiment, the preset value table of the higher sub-data segment in the mantissa data segment corresponding to different types of calculation modes is pre-stored, instead of the preset value table corresponding to the entire mantissa data segment, which reduces the storage capacity of the preset value table. Improved the speed of checking the preset value table. In addition, different types of calculation modes reuse addition units and multipliers, and perform simple linear operations to obtain the results of various types of nonlinear complex operations, reduce hardware costs, and improve computing efficiency.
在一些实施例中,所述尾数数据段的所述高位子数据段的位数与所述低位子数据位的位数之和等于所述尾数数据段的位数。以尾数数据段的位数为23位为例(如图4所示),如m0-m22,若高位子数据段的位数为9,也就是m0-m8,则相应地,低位子数据段的位数为14,也就是m9-m22。In some embodiments, the sum of the number of bits in the high-order sub-data segment and the number of low-order sub-data bits of the mantissa data segment is equal to the number of bits in the mantissa data segment. Take 23 bits in the mantissa data segment as an example (as shown in Figure 4), such as m0-m22, if the number of bits in the upper sub-data segment is 9, that is, m0-m8, correspondingly, the lower sub-data segment The number of digits is 14, which is m9-m22.
可选地,所述高位子数据段的位数与所述尾数数据段的位数,根据对应所述泰勒展开的余项部分的精度确定。例如:余项部分的精度为小于等于2-18,则高位子数据段的位数为9。因为在关于在所述计算模式下的运算结果的计算中,省略了对应所述泰勒展开的余项部分,所以余项部分的精度实际上与运算结果的精度有关。因此,本实施例可以根据实际需要调整运算结果的精度。Optionally, the number of bits in the upper sub-data segment and the number of bits in the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion. For example: if the precision of the remainder part is less than or equal to 2-18, the number of bits in the upper sub-data segment is 9. Because in the calculation of the calculation result in the calculation mode, the remainder part corresponding to the Taylor expansion is omitted, so the accuracy of the remainder part is actually related to the accuracy of the calculation result. Therefore, in this embodiment, the accuracy of the calculation result can be adjusted according to actual needs.
在一些实施例中,上述的加法运算单元包括选择器和加法器,相应地,上述S204的一种可能的实现方式可以包括S2041和S2042:In some embodiments, the above-mentioned addition operation unit includes a selector and an adder. Accordingly, a possible implementation of the above-mentioned S204 may include S2041 and S2042:
S2041、将所述低位子数据段的数值输入所述选择器,以使所述选择器为所述低位子数据段的数值赋予与所述计算模式对应的运算系数,获得第三值。S2041. Input the numerical value of the low-order sub-data segment to the selector, so that the selector assigns the numerical value of the low-order sub-data segment to the calculation coefficient corresponding to the calculation mode to obtain a third value.
S2042、将所述高位子数据段的数值和所述第三值输入所述加法器,得到所述第二值。S2042. Input the numerical value of the high-order sub-data segment and the third value to the adder to obtain the second value.
本实施例中,将低位子数据段的数值输入选择器中,选择器为该低位子数据段的数值赋予与该计算模式对应的运算系数,获得第三值,其中,针对不同种类的计算模式,为低位子数据位的数值赋予的运算系数可能不同。例如:第三值与该低位子数据段的数值相乘的结果作为第三值。In this embodiment, the numerical value of the low-order sub-data segment is input into the selector, and the selector assigns the numerical value of the low-order sub-data segment to the calculation coefficient corresponding to the calculation mode to obtain the third value, wherein, for different types of calculation modes , The calculation coefficients assigned to the lower sub-data bits may be different. For example: the third value is multiplied by the value of the lower sub-data segment as the third value.
在获得第三值之后,将高位子数据段的数值和第三值输入加法器,加法器对高位子数据段的数值与第三值相加,将相加获得的值作为第二值。After the third value is obtained, the numerical value of the high-order sub-data segment and the third value are input to the adder, and the adder adds the numerical value of the high-order sub-data segment to the third value, and the value obtained by the addition is used as the second value.
因此,本实施例复用了选择器、加法器和乘法器,进行的是简单的加法和乘法运算即可获得多种类非线性复杂运算的结果,降低了硬件成本,提高了运算效率。Therefore, this embodiment multiplexes selectors, adders, and multipliers, and performs simple addition and multiplication operations to obtain results of various types of nonlinear complex operations, reduces hardware costs, and improves operation efficiency.
在一些实施例中,若所述计算模式包括计算倒数,则所述第一运算公式 为
Figure PCTCN2019108872-appb-000004
所述加法运算公式为a+(-1)t。若所述计算模式包括计算开方,则所述第一运算公式为
Figure PCTCN2019108872-appb-000005
所述加法运算公式为
Figure PCTCN2019108872-appb-000006
若所述计算模式包括计算开方倒数,则所述第一运算公式为
Figure PCTCN2019108872-appb-000007
所述加法运算公式为
Figure PCTCN2019108872-appb-000008
其中,a为所述高位子数据段的数值,t为所述低位子数据段的数值。
In some embodiments, if the calculation mode includes calculating the reciprocal, the first calculation formula is
Figure PCTCN2019108872-appb-000004
The addition operation formula is a+(-1)t. If the calculation mode includes a square root, the first calculation formula is
Figure PCTCN2019108872-appb-000005
The addition operation formula is
Figure PCTCN2019108872-appb-000006
If the calculation mode includes calculating the reciprocal root, the first calculation formula is
Figure PCTCN2019108872-appb-000007
The addition operation formula is
Figure PCTCN2019108872-appb-000008
Wherein, a is the value of the upper sub-data segment, and t is the value of the lower sub-data segment.
其中,选择器可以根据计算模式包括计算倒数,选择为t赋予的运算系数为-1,获得第三值为(-1)t;选择器可以根据计算模式包括计算开方,选择为t n赋予的运算系数为
Figure PCTCN2019108872-appb-000009
获得第三值为
Figure PCTCN2019108872-appb-000010
选择器可以根据计算模式包括计算开方倒数,选择为t赋予的运算系数为
Figure PCTCN2019108872-appb-000011
获得第三值为
Figure PCTCN2019108872-appb-000012
Among them, the selector may include calculating the reciprocal according to the calculation mode, the calculation coefficient assigned to t is -1, and the third value is (-1)t; the selector may include calculating the square root according to the calculation mode, and the selection is assigned to t n The calculation coefficient is
Figure PCTCN2019108872-appb-000009
Get the third value
Figure PCTCN2019108872-appb-000010
The selector can include calculating the reciprocal root of the square according to the calculation mode, and select the calculation coefficient given to t as
Figure PCTCN2019108872-appb-000011
Get the third value
Figure PCTCN2019108872-appb-000012
在一些实施例中,上述S205中根据所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值的一种可能的实现方式可以包括S2051-S2052:In some embodiments, a possible implementation manner of obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the first product result in the foregoing S205 may include S2051-S2052:
S2051、获取所述第一乘积结果中第一预设数值之后的预设位数的数值。S2051. Obtain the value of the preset number of digits after the first preset value in the first product result.
S2052、根据所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。S2052, according to the value of the preset number of digits, obtain the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
本实施例中,预设位数为所述尾数数据段的位数,该尾数数据段的位数例如为23位。In this embodiment, the preset number of bits is the number of bits in the mantissa data segment, and the number of bits in the mantissa data segment is, for example, 23 bits.
确定第一乘积结果中从高位到低位的顺序中第一个第一预设数值的位数,该位数例如称为第K位,获取第一乘积结果中从高位到低位的顺序中第K+1位至第K+23位的数值,然后根据该第K+1位至第K+23位的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。上述的第一预设数值例如为1。Determine the number of digits of the first preset value in the order from high to low in the first product result. This digit is called the Kth digit, for example, and obtain the Kth in the order from high to low in the first product result. +1 to K+23 digits, and then according to the K+1 digits to K+23 digits, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained. The above-mentioned first preset value is, for example, 1.
在一些实施例中,上述S2052的一种可能的实现方式可以为:In some embodiments, a possible implementation manner of the foregoing S2052 may be:
如果上述计算模式包括计算倒数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。也就是,将第一乘积结果中从高位到低位的顺序中第K+1位至第K+23位的数值确定为所述浮点数在所述计算倒数下的运算结果的尾数数据段的数值。If the above calculation mode includes the reciprocal calculation, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating point number in the calculation mode. That is, the value of the K+1 to K+23 in the order from high to low in the first product result is determined as the value of the mantissa data segment of the operation result of the floating-point number under the reciprocal calculation .
如果所述计算模式包括计算开方或者计算开方倒数,则根据所述浮点数的指数数据段的数值的奇偶性以及所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the floating-point number is obtained in the calculation mode according to the parity of the value of the exponent data segment of the floating-point number and the value of the preset number of bits. The value of the mantissa data field of the operation result below.
例如:计算模式为计算开方,若浮点数的指数数据段的数值为奇数,则所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值,也就是,将第一乘积结果中从高位到低位的顺序中第K+1位至第K+23位的数值确定为所述浮点数在所述计算开方或计算开方倒数下的运算结果的尾数数据段的数值。For example: the calculation mode is calculation root, if the value of the exponent data segment of the floating-point number is an odd number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode , That is, the value of the K+1 to K+23 in the order from high to low in the first product result is determined as the operation of the floating-point number under the square root of the calculation or the reciprocal root of the calculation The value of the mantissa data segment of the result.
若浮点数的指数数据段的数值为偶数,则将所述预设位数的数值以及第二预设数值输入第二乘法器,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。可选地,该第二预设数值例如为
Figure PCTCN2019108872-appb-000013
获得第二乘积结果之后,确定第二乘积结果中从高位到低位的顺序中第一个第一预设数值(例如1)的位数,该位数例如称为第P位,获取第二乘积结果中从高位到低位的顺序中第P+1位至第P+23位的数值,并将该第P+1位至第P+23位的数值确定为所述浮点数在所述计算开方或计算开方倒数下的运算结果的尾数数据段的数值。
If the value of the exponent data segment of the floating-point number is an even number, the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode. Optionally, the second preset value is, for example,
Figure PCTCN2019108872-appb-000013
After obtaining the second product result, determine the number of digits of the first first preset value (for example, 1) in the order from high to low in the second product result. This digit is called, for example, the Pth digit, and the second product is obtained The value from the P+1 digit to the P+23 digit in the order from high to low in the result, and the value from the P+1 digit to the P+23 digit is determined as the floating point number in the calculation. Or calculate the value of the mantissa data segment of the operation result under the reciprocal root of the square.
例如:计算模式为计算开方倒数,若浮点数的指数数据段的数值为偶数,则所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。若所述指数数据段的数值为奇数,则将所述预设位数的数值以及第二预设数值输入第二乘法器,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。For example: the calculation mode is to calculate the reciprocal root. If the value of the exponent data segment of the floating-point number is an even number, the value of the preset digits is used as the mantissa data segment of the operation result of the floating-point number in the calculation mode Numerical value. If the value of the exponent data segment is an odd number, the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after a preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
针对浮点数中的符号数据段,在一些实施例中,在获取到浮点数的处理指令之后,在符号数据段的存储地址,获取浮点数的符号数据段的数值,并根据该符号数据段的数值,获得该浮点数在计算模式下的运算结果的符号数据段的数值并且存入对应所述浮点数在所述计算模式下的运算结果的符号数据段地址。For the symbol data segment of the floating-point number, in some embodiments, after the processing instruction of the floating-point number is acquired, the value of the symbol data segment of the floating-point number is acquired at the storage address of the symbol data segment, and the value of the symbol data segment is obtained according to the symbol data segment. Numerical value, the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and the address of the symbol data segment corresponding to the operation result of the floating-point number in the calculation mode is stored.
若所述计算模式包括计算倒数,则将所述符号数据段的数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值。If the calculation mode includes the reciprocal calculation, the value of the symbol data segment is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
若所述计算模式包括计算开方或者计算开方倒数,则将第三预设数值(例如为0)作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the third preset value (for example, 0) is used as the value of the symbol data segment of the calculation result of the floating-point number in the calculation mode.
针对浮点数中的指数数据段,在一些实施例中,在获取到浮点数的处理 指令之后,在所述指数数据段的存储地址,读取所述指数数据段的数值;根据所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值并且存入对应所述浮点数在所述计算模式下的运算结果的指数数据段地址。For the exponent data segment in the floating-point number, in some embodiments, after obtaining the processing instruction of the floating-point number, read the value of the exponent data segment at the storage address of the exponent data segment; according to the exponent data The value of the segment, the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and the address of the exponent data segment corresponding to the operation result of the floating-point number in the calculation mode is stored.
若所述计算模式包括计算倒数,则根据所述尾数数据段的数值以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值。可选地,若所述尾数数据段的数值为第三预设值,则将254-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;若所述尾数数据段的数值不为第三预设值,则将253-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值。 If the calculation mode includes the reciprocal calculation, the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained according to the value of the mantissa data segment and the value of the exponent data segment. Optionally, if the value of the mantissa data segment is the third preset value, the value of 254-E i is used as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode; If the value of the mantissa data segment is not the third preset value, the value of 253-E i is used as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode.
若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
可选地,所述计算模式包括计算开方,若所述指数数据段的数值为奇数,则将
Figure PCTCN2019108872-appb-000014
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;若所述指数数据段的数值为偶数,则将
Figure PCTCN2019108872-appb-000015
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值。
Optionally, the calculation mode includes calculating a square root, and if the value of the exponent data segment is an odd number, then
Figure PCTCN2019108872-appb-000014
Determined as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode; if the value of the exponent data segment is an even number, then
Figure PCTCN2019108872-appb-000015
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode.
可选地,所述计算模式包括计算开方倒数,若所述指数数据段的数值为奇数且所述尾数数据段的数值不等于第三预设数值,则将
Figure PCTCN2019108872-appb-000016
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;若所述指数数据段的数值为奇数且所述尾数数据段的数值等于第三预设数值,则将
Figure PCTCN2019108872-appb-000017
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;若所述指数数据段的数值为偶数,则将
Figure PCTCN2019108872-appb-000018
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值。
Optionally, the calculation mode includes calculating the reciprocal root, and if the value of the exponent data segment is an odd number and the value of the mantissa data segment is not equal to a third preset value, then
Figure PCTCN2019108872-appb-000016
Determine the value of the exponent data segment as the result of the calculation of the floating-point number in the calculation mode; if the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then
Figure PCTCN2019108872-appb-000017
Determined as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode; if the value of the exponent data segment is an even number, then
Figure PCTCN2019108872-appb-000018
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode.
其中,上述的E i为运算前的所述指数数据段的数值。 Wherein, the aforementioned E i is the value of the exponent data segment before the calculation.
下面结合图5所示的硬件架构,对浮点数的计算倒数、计算开方、计算开方倒数的进行举例描述,其中,计算倒数、计算开方、计算开方倒数前的浮点数的符号数据段为S i,指数数据段为E i,尾数数据段为M i。计算倒数或计算开方或计算开方倒数是分别对符号数据段为S i,指数数据段为E i,尾数数据段为M i进行计算,经计算后的获得的符号数据段为S 0,指数数据段为E 0, 尾数数据段为M 0The following describes the calculation of the reciprocal of floating-point numbers, the calculation of the square root, and the calculation of the reciprocal root of a floating-point number with the hardware architecture shown in Figure 5. Among them, the calculation of the reciprocal, the calculation of the square root, and the calculation of the sign data of the floating-point number before the reciprocal root segment S i, the index data segment E i, mantissa data segment M i. Or the reciprocal of the square root calculation, or the reciprocal square root is calculated for each symbol data segment S i, the index data segment E i, the mantissa data segment is calculated as M i, symbol data segment obtained after calculation is S 0, The exponent data segment is E 0 , and the mantissa data segment is M 0 .
对浮点数计算倒数:Calculate the reciprocal of a floating point number:
Figure PCTCN2019108872-appb-000019
Figure PCTCN2019108872-appb-000019
因此,由上述式子可以得到S 0=S i
Figure PCTCN2019108872-appb-000020
Therefore, S 0 =S i can be obtained from the above formula,
Figure PCTCN2019108872-appb-000020
其中,当M i=0,则E 0=2*127-E i=254-E i,当M i≠0,则E 0=2*127-E i-1=253-E iWherein, when M i = 0, then E 0 = 2 * 127-E i = 254-E i, when M i ≠ 0, then E 0 = 2 * 127-E i -1 = 253-E i.
S 0和E 0容易计算获得,因此,计算浮点数的倒数的关键是计算
Figure PCTCN2019108872-appb-000021
的数值。下面主要说明M 0如何计算获得,其中,利用泰勒公式对
Figure PCTCN2019108872-appb-000022
展开以便计算。
S 0 and E 0 are easy to calculate. Therefore, the key to calculating the reciprocal of a floating-point number is to calculate
Figure PCTCN2019108872-appb-000021
The numerical value. The following mainly explains how to calculate M 0 , among which, the Taylor formula is used to
Figure PCTCN2019108872-appb-000022
Expand for calculation.
令x=a n+t n=1.M i,计算模式为计算倒数,则设函数一: Let x=a n +t n =1.M i , and the calculation mode is the reciprocal calculation, then set function one:
Figure PCTCN2019108872-appb-000023
由此可知,f(x)∈(0.5,1]
Figure PCTCN2019108872-appb-000023
It can be seen that f(x)∈(0.5,1]
对该函数一进行一阶展开:Perform a first-order expansion on this function one:
Figure PCTCN2019108872-appb-000024
Figure PCTCN2019108872-appb-000024
且一阶泰勒误差项表示为:And the first-order Taylor error term is expressed as:
Figure PCTCN2019108872-appb-000025
Figure PCTCN2019108872-appb-000025
如果计算的结果精确到尾数位的第18位,即If the calculated result is accurate to the 18th digit of the mantissa, that is
Figure PCTCN2019108872-appb-000026
这样,t n≤2 -9
Figure PCTCN2019108872-appb-000026
Thus, t n ≤ 2 -9 .
其中,a n包括隐含位1以及浮点数的尾数数据段中m0-m8共9位,t n为浮点数的尾数数据段中m9-m22共14位。 Among them, a n includes a total of 9 bits in the mantissa data segment of the floating-point number and m0-m8, and t n is a total of 14 bits in the mantissa data segment of the floating-point number.
而且上述函数一可以简化为
Figure PCTCN2019108872-appb-000027
因此,当计算倒数时,上述的第一运算公式为
Figure PCTCN2019108872-appb-000028
上述加法运算公式为a n+(-1)t n
And the above function one can be simplified to
Figure PCTCN2019108872-appb-000027
Therefore, when calculating the reciprocal, the first arithmetic formula above is
Figure PCTCN2019108872-appb-000028
The above-mentioned addition operation formula is a n +(-1)t n .
同时,a n可以表示为:
Figure PCTCN2019108872-appb-000029
且k为整数。根据k的不同取值,计算
Figure PCTCN2019108872-appb-000030
从而预先获得对应计算倒数的预设数值表并存储,其中k由m0至m8确定。
Meanwhile, a n may be expressed as:
Figure PCTCN2019108872-appb-000029
And k is an integer. According to the different values of k, calculate
Figure PCTCN2019108872-appb-000030
Thereby, a preset value table corresponding to the calculated reciprocal is obtained in advance and stored, where k is determined by m0 to m8.
基于图5所示,当需要计算浮点数的倒数时,在第一阶段,选择器1根 据选择的计算模式为计算倒数,选择为E i赋予系数-1,并向加法器1输出-E i。选择器2根据选择的计算模式为计算倒数,从选择器3、选择器4、选择器5中确定与计算倒数对应的选择器3。如果浮点数的M 0的数值为0,则选择选择器3中的254并输出给加法器1,加法器1输出E′ i=254-E i给选择器6,如果浮点数的M 0的数值不为0,则选择选择器4中的253并输出给加法器1,加法器1输出E′ i=253-E i给选择器6。选择器7根据选择的计算模式为计算倒数,选择-t n,为浮点数中尾数数据段的低位子数据段(t n)赋予-1的系数,并输出给加法器2,同时浮点数中尾数数据段的高位子数据段(a n)输入至加法器2中,加法器2输出(a n-t n)给乘法器1。 Based on Figure 5, when the reciprocal of a floating-point number needs to be calculated, in the first stage, the selector 1 calculates the reciprocal according to the selected calculation mode, selects E i to assign the coefficient -1, and outputs -E i to the adder 1 . The selector 2 calculates the reciprocal according to the selected calculation mode, and determines the selector 3 corresponding to the calculated reciprocal from the selector 3, the selector 4, and the selector 5. If the value of M 0 of the floating-point number is 0, select 254 in selector 3 and output to adder 1, and adder 1 outputs E′ i =254-E i to selector 6, if the value of M 0 of floating-point number If the value is not 0, 253 in selector 4 is selected and output to adder 1, and adder 1 outputs E′ i =253-E i to selector 6. The selector 7 calculates the reciprocal according to the selected calculation mode, selects -t n , assigns a coefficient of -1 to the lower sub-data segment (t n ) of the mantissa data segment in the floating-point number, and outputs it to the adder 2, and the floating-point number The high-order sub-data segment (a n ) of the mantissa data segment is input to the adder 2, and the adder 2 outputs (a n -t n ) to the multiplier 1.
另外,从存储的预设数值表中,获取计算倒数对应的预设数值表,根据浮点数中的a n,从预设数值表中获取
Figure PCTCN2019108872-appb-000031
的值并输出给乘法器1。
In addition, obtain the preset value table corresponding to the calculated reciprocal from the stored preset value table, and obtain from the preset value table according to the a n in the floating point number
Figure PCTCN2019108872-appb-000031
And output to the multiplier 1.
第二阶段,选择器6根据选择的计算模式为计算倒数,选择为E′ i赋予系数1获得E 0=E′ i并输出给寄存器1。乘法器1将(a n-t n)与
Figure PCTCN2019108872-appb-000032
相乘,获得
Figure PCTCN2019108872-appb-000033
的值与(a n-t n)的值的乘积,该乘积例如为48bit,确定该48bit的乘积中第一个1的位置,该位作为M 0的隐含位,从该位的下一位开始从高位到低位的顺序取23bit,即获得24bit,并将该24位存入寄存器2中。
In the second stage, the selector 6 calculates the reciprocal according to the selected calculation mode, and chooses to assign the coefficient 1 to E′ i to obtain E 0 =E′ i and output it to the register 1. Multiplier 1 will (a n -t n ) and
Figure PCTCN2019108872-appb-000032
Multiply to get
Figure PCTCN2019108872-appb-000033
The product of the value of and the value of (a n -t n ). The product is 48 bits, for example. Determine the position of the first 1 in the product of 48 bits. This bit is the hidden bit of M 0. The bit starts from the high bit to the low bit and takes 23 bits in order, that is, 24 bits are obtained, and the 24 bits are stored in register 2.
第三阶段,选择器8根据选择的计算模式为计算倒数,从寄存器2中获取该24bit的值并输出,以获得M 0。另外,获取寄存器1中存储的E 0并输出。同时,选择器9根据选择的计算模式为计算倒数,选择输出S 0=S i。在第三阶段计算S 0,以及将E 0暂时存储在寄存器,可以保证运算结果中S 0、E 0、M 0的时序同步。 In the third stage, the selector 8 calculates the reciprocal according to the selected calculation mode, obtains the 24-bit value from the register 2 and outputs it to obtain M 0 . In addition, the E 0 stored in the register 1 is obtained and output. At the same time, the selector 9 calculates the reciprocal according to the selected calculation mode, and selects the output S 0 =S i . Calculating S 0 in the third stage and temporarily storing E 0 in the register can ensure that the timing of S 0 , E 0 , and M 0 in the operation result is synchronized.
因此,本实施例存储有
Figure PCTCN2019108872-appb-000034
的运算结果的预设数据表,通过查表和简单的加法、乘法运算来获得浮点数的倒数,由于本实施例只存储尾数数据段中高位子数据段的运算结果,降低了预设数据表的存储量,降低了硬件成本,还提高了运算效率。
Therefore, this embodiment stores
Figure PCTCN2019108872-appb-000034
The reciprocal of the floating-point number is obtained by looking up the table and simple addition and multiplication operations in the preset data table of the operation result. Since this embodiment only stores the operation result of the upper sub-data section in the mantissa data section, the pre-set data table is reduced The storage capacity reduces the hardware cost and also improves the computing efficiency.
对浮点数计算开方:Calculate the square root of floating-point numbers:
Figure PCTCN2019108872-appb-000035
Figure PCTCN2019108872-appb-000035
因此,由上述式子可以得到:Therefore, from the above formula, we can get:
由于对负数进行开方属于无效操作,因此S 0=0。 Since the square root of a negative number is an invalid operation, S 0 =0.
若E i为奇数,则
Figure PCTCN2019108872-appb-000036
若E i为偶数,则
Figure PCTCN2019108872-appb-000037
If E i is odd, then
Figure PCTCN2019108872-appb-000036
If E i is even, then
Figure PCTCN2019108872-appb-000037
若E i为奇数,则
Figure PCTCN2019108872-appb-000038
若E i为偶数,则
Figure PCTCN2019108872-appb-000039
这里的
Figure PCTCN2019108872-appb-000040
可以用24'hB504F3表示。
If E i is odd, then
Figure PCTCN2019108872-appb-000038
If E i is even, then
Figure PCTCN2019108872-appb-000039
here
Figure PCTCN2019108872-appb-000040
It can be represented by 24'hB504F3.
S 0和E 0容易计算获得,因此,计算浮点数的倒数的关键是计算
Figure PCTCN2019108872-appb-000041
的数值。下面主要说明M 0如何计算获得,其中,利用泰勒公式对
Figure PCTCN2019108872-appb-000042
展开以便计算。
S 0 and E 0 are easy to calculate. Therefore, the key to calculating the reciprocal of a floating-point number is to calculate
Figure PCTCN2019108872-appb-000041
The numerical value. The following mainly explains how to calculate M 0 , among which, the Taylor formula is used to
Figure PCTCN2019108872-appb-000042
Expand for calculation.
令x=a n+t n=1.M i,计算模式为计算倒数,则设函数二: Let x=a n +t n =1.M i , and the calculation mode is the reciprocal calculation, then set the function two:
Figure PCTCN2019108872-appb-000043
由此可知,
Figure PCTCN2019108872-appb-000044
Figure PCTCN2019108872-appb-000043
It can be seen that
Figure PCTCN2019108872-appb-000044
对该函数二进行一阶展开:Perform a first-order expansion on this function two:
Figure PCTCN2019108872-appb-000045
Figure PCTCN2019108872-appb-000045
且一阶泰勒误差项表示为:And the first-order Taylor error term is expressed as:
Figure PCTCN2019108872-appb-000046
Figure PCTCN2019108872-appb-000046
如果计算的结果精确到尾数位的第18位,即If the calculated result is accurate to the 18th digit of the mantissa, that is
Figure PCTCN2019108872-appb-000047
这样,t n≤2 -9
Figure PCTCN2019108872-appb-000047
Thus, t n ≤ 2 -9 .
其中,a n包括隐含位1以及浮点数的尾数数据段中m0-m8共9位,t n为浮点数的尾数数据段中m9-m22共14位。 Among them, a n includes a total of 9 bits in the mantissa data segment of the floating-point number and m0-m8, and t n is a total of 14 bits in the mantissa data segment of the floating-point number.
而且上述函数二可以简化为
Figure PCTCN2019108872-appb-000048
因此,当计算开方时,上述的第一运算公式为
Figure PCTCN2019108872-appb-000049
上述加法运算公式为
Figure PCTCN2019108872-appb-000050
And the above function two can be simplified to
Figure PCTCN2019108872-appb-000048
Therefore, when calculating the square root, the first arithmetic formula above is
Figure PCTCN2019108872-appb-000049
The above addition formula is
Figure PCTCN2019108872-appb-000050
同时,a n可以表示为:
Figure PCTCN2019108872-appb-000051
且k为整数。根据k的不同取值,计算
Figure PCTCN2019108872-appb-000052
从而预先获得对应计算开方的预设数值表并存储,其中k由m0至m8确定。
Meanwhile, a n may be expressed as:
Figure PCTCN2019108872-appb-000051
And k is an integer. According to the different values of k, calculate
Figure PCTCN2019108872-appb-000052
Thereby, a preset numerical table corresponding to the square root of the calculation is obtained in advance and stored, where k is determined by m0 to m8.
基于图5所示,当需要计算浮点数的开方时,在第一阶段,选择器1根据选择的计算模式为计算开方,选择为E i赋予系数1,并向加法器1输出E i。选择器2根据选择的计算模式为计算开方,从选择器3、选择器4、选择器5中确定与计算开方对应的选择器4。如果浮点数的E i为奇数,则选择选择器4中的127并输出给加法器1,加法器1输出E′ i=E i+127给选择器6,如果浮点 数的E i为偶数,则选择选择器4中的126并输出给加法器1,加法器1输出E′ i=E i+126给选择器6。 Based on Figure 5, when the square root of a floating-point number needs to be calculated, in the first stage, the selector 1 calculates the square root according to the selected calculation mode, selects E i to assign a coefficient of 1, and outputs E i to the adder 1 . The selector 2 is the calculation root based on the selected calculation mode, and the selector 4 corresponding to the calculation root is determined from the selector 3, the selector 4, and the selector 5. If E i of the floating-point number is odd, select 127 in selector 4 and output to adder 1, and adder 1 outputs E′ i =E i +127 to selector 6, if E i of the floating-point number is even, Then 126 in the selector 4 is selected and output to the adder 1, and the adder 1 outputs E′ i =E i +126 to the selector 6.
选择器7根据选择的计算模式为计算开方,选择t n<<1,为浮点数中尾数数据段的低位子数据段(t n)赋予
Figure PCTCN2019108872-appb-000053
的系数,并输出给加法器2,同时浮点数中尾数数据段的高位子数据段(a n)输入至加法器2中,加法器2输出
Figure PCTCN2019108872-appb-000054
给乘法器1。另外,从存储的预设数值表中,获取计算开方对应的预设数值表,根据浮点数中的a n,从预设数值表中获取
Figure PCTCN2019108872-appb-000055
的值并输出给乘法器1。
The selector 7 calculates the square root according to the selected calculation mode, selects t n <<1, and assigns the low-order sub-data segment (t n ) of the mantissa data segment in the floating-point number
Figure PCTCN2019108872-appb-000053
And output to adder 2. At the same time, the high-order sub-data segment (a n ) of the mantissa data segment in the floating-point number is input to adder 2, and adder 2 outputs
Figure PCTCN2019108872-appb-000054
Give the multiplier 1. In addition, obtain the preset value table corresponding to the square root from the stored preset value table, and obtain it from the preset value table according to the a n in the floating point number
Figure PCTCN2019108872-appb-000055
And output to the multiplier 1.
第二阶段,选择器6根据选择的计算模式为计算开方,选择E′ i>>1为E′ i赋予系数
Figure PCTCN2019108872-appb-000056
获得
Figure PCTCN2019108872-appb-000057
并输出给寄存器1。乘法器1将
Figure PCTCN2019108872-appb-000058
Figure PCTCN2019108872-appb-000059
相乘,获得
Figure PCTCN2019108872-appb-000060
的值与
Figure PCTCN2019108872-appb-000061
的值的乘积,该乘积例如为48bit,确定该48bit的乘积中第一个1的位置,从该位的下一位开始从高位到低位的顺序取23bit,即获得24bit,并将该24位存入寄存器2以及还将该24位输出给乘法器2。
In the second stage, the selector 6 calculates the square root according to the selected calculation mode, and selects E′ i >>1 to assign coefficients to E′ i
Figure PCTCN2019108872-appb-000056
obtain
Figure PCTCN2019108872-appb-000057
And output to register 1. Multiplier 1 will
Figure PCTCN2019108872-appb-000058
versus
Figure PCTCN2019108872-appb-000059
Multiply to get
Figure PCTCN2019108872-appb-000060
And the value of
Figure PCTCN2019108872-appb-000061
The product of the value of, the product is 48bit, for example, determine the position of the first 1 in the product of 48bit, and take 23bit from the next bit of the bit from high to low, that is, 24bit is obtained, and the 24bit Store in register 2 and output the 24 bits to multiplier 2.
第三阶段,乘法器2对输入的24位的数值乘
Figure PCTCN2019108872-appb-000062
输出48比特的乘积,然后确定该48bit的乘积中第一个1的位置,从该位的下一位开始从高位到低位的顺序取23bit,即获得24bit。如果E i为奇数,选择器8选择从寄存器2中获取该24bit的值并输出,以获得M 0,如果E i为偶数,选择器8选择通过乘法器2获得的24bit的值并输出,以获得M 0。另外,获取寄存器1中存储的E 0并输出。同时,选择器9根据选择的计算模式为计算开方,选择输出S 0=0。在第三阶段计算S 0,以及将E 0暂时存储在寄存器,可以保证运算结果中S 0、E 0、M 0的时序同步。
In the third stage, the multiplier 2 multiplies the input 24-bit value
Figure PCTCN2019108872-appb-000062
Output a 48-bit product, and then determine the position of the first 1 in the 48-bit product. From the next bit of the bit, take 23 bits from high to low to obtain 24 bits. If E i is an odd number, selector 8 chooses to obtain the 24-bit value from register 2 and output it to obtain M 0 , if E i is an even number, selector 8 selects the 24-bit value obtained through multiplier 2 and outputs it to Obtain M 0 . In addition, the E 0 stored in the register 1 is obtained and output. At the same time, the selector 9 calculates the square root according to the selected calculation mode, and selects the output S 0 =0. Calculating S 0 in the third stage and temporarily storing E 0 in the register can ensure that the timing of S 0 , E 0 , and M 0 in the operation result is synchronized.
因此,本实施例存储有
Figure PCTCN2019108872-appb-000063
的运算结果的预设数据表,通过查表和简单的加法、乘法运算来获得浮点数的开方,由于本实施例只存储尾数数据段中高位子数据段的运算结果,降低了预设数据表的存储量,降低了硬件成本,还提高了运算效率。
Therefore, this embodiment stores
Figure PCTCN2019108872-appb-000063
The pre-set data table of the calculation result of the calculation result is obtained by looking up the table and simple addition and multiplication operations to obtain the root of the floating-point number. Since this embodiment only stores the calculation result of the upper sub-data section in the mantissa data section, the preset data table is reduced The storage capacity reduces the hardware cost and also improves the computing efficiency.
对浮点数计算开方倒数:Calculate the reciprocal root of a floating-point number:
Figure PCTCN2019108872-appb-000064
Figure PCTCN2019108872-appb-000064
因此,由上述式子可以得到:Therefore, from the above formula, we can get:
由于对负数进行开方属于无效操作,因此S 0=0。 Since the square root of a negative number is an invalid operation, S 0 =0.
若E i为奇数且M i=0,则
Figure PCTCN2019108872-appb-000065
若E i为奇数且M i≠0,则
Figure PCTCN2019108872-appb-000066
若E i为偶数,则
Figure PCTCN2019108872-appb-000067
If E i is odd and M i =0, then
Figure PCTCN2019108872-appb-000065
If E i is odd and M i ≠ 0, then
Figure PCTCN2019108872-appb-000066
If E i is even, then
Figure PCTCN2019108872-appb-000067
若E i为奇数,则
Figure PCTCN2019108872-appb-000068
若E i为偶数,则
Figure PCTCN2019108872-appb-000069
这里的
Figure PCTCN2019108872-appb-000070
可以用24'hB504F3表示。
If E i is odd, then
Figure PCTCN2019108872-appb-000068
If E i is even, then
Figure PCTCN2019108872-appb-000069
here
Figure PCTCN2019108872-appb-000070
It can be represented by 24'hB504F3.
S 0和E 0容易计算获得,因此,计算浮点数的倒数的关键是计算
Figure PCTCN2019108872-appb-000071
的数值。下面主要说明M 0如何计算获得,其中,利用泰勒公式对
Figure PCTCN2019108872-appb-000072
展开以便计算。
S 0 and E 0 are easy to calculate. Therefore, the key to calculating the reciprocal of a floating-point number is to calculate
Figure PCTCN2019108872-appb-000071
The numerical value. The following mainly explains how to calculate M 0 , among which, the Taylor formula is used to
Figure PCTCN2019108872-appb-000072
Expand for calculation.
令x=a n+t n=1.M i,计算模式为计算倒数,则设函数三: Let x=a n +t n =1.M i , the calculation mode is the reciprocal calculation, then set the function three:
Figure PCTCN2019108872-appb-000073
由此可知,
Figure PCTCN2019108872-appb-000074
Figure PCTCN2019108872-appb-000073
It can be seen that
Figure PCTCN2019108872-appb-000074
对该函数三进行一阶展开:Perform a first-order expansion on this function three:
Figure PCTCN2019108872-appb-000075
Figure PCTCN2019108872-appb-000075
且一阶泰勒误差项表示为:And the first-order Taylor error term is expressed as:
Figure PCTCN2019108872-appb-000076
Figure PCTCN2019108872-appb-000076
如果计算的结果精确到尾数位的第18位,即If the calculated result is accurate to the 18th digit of the mantissa, that is
Figure PCTCN2019108872-appb-000077
这样,t n≤2 -9
Figure PCTCN2019108872-appb-000077
Thus, t n ≤ 2 -9 .
其中,a n包括隐含位1以及浮点数的尾数数据段中m0-m8共9位,t n为浮点数的尾数数据段中m9-m22共14位。 Among them, a n includes a total of 9 bits in the mantissa data segment of the floating-point number and m0-m8, and t n is a total of 14 bits in the mantissa data segment of the floating-point number.
而且上述函数三可以简化为
Figure PCTCN2019108872-appb-000078
同时,a n可以表示为:
Figure PCTCN2019108872-appb-000079
且k为整数。
And the above function three can be simplified to
Figure PCTCN2019108872-appb-000078
Meanwhile, a n may be expressed as:
Figure PCTCN2019108872-appb-000079
And k is an integer.
在一种可能的实现方式中,上述的第一运算公式可以设为
Figure PCTCN2019108872-appb-000080
上述的第一运算公式可以设为
Figure PCTCN2019108872-appb-000081
上述加法运算公式为
Figure PCTCN2019108872-appb-000082
根据k的不同取值,计算
Figure PCTCN2019108872-appb-000083
从而预先获得对应计算开方倒数的预设数值表并存储,其中k由m0至m8确定。
In a possible implementation, the above-mentioned first calculation formula can be set as
Figure PCTCN2019108872-appb-000080
The above first calculation formula can be set as
Figure PCTCN2019108872-appb-000081
The above addition formula is
Figure PCTCN2019108872-appb-000082
According to the different values of k, calculate
Figure PCTCN2019108872-appb-000083
Thereby, a preset numerical table corresponding to the reciprocal root of the calculation is obtained in advance and stored, where k is determined by m0 to m8.
基于图5所示,当需要计算浮点数的开方倒数时,在第一阶段,选择器1根据选择的计算模式为计算开方倒数,选择为E i赋予系数-1,并向加法器1输出-E i。选择器2根据选择的计算模式为计算开方倒数,从选择器3、选择器4、选择器5中确定与计算开方倒数对应的选择器5。如果浮点数的E i为奇数且M 0的数值为0,则选择选择器5中的381并输出给加法器1,加法器1输出E′ i=381-E i给选择器6,如果浮点数的E i为奇数且M 0的数值不为0,则选择选择器5中的379并输出给加法器1,加法器1输出E′ i=379-E i给选择器6,如果浮点数的E i为偶数,则选择选择器5中的380并输出给加法器1,加法器1输出E′ i=380-E i给选择器6。 Based on Figure 5, when it is necessary to calculate the reciprocal root of a floating-point number, in the first stage, the selector 1 calculates the reciprocal root according to the selected calculation mode, chooses to assign a coefficient of -1 to E i , and sends it to the adder 1 Output -E i . The selector 2 calculates the reciprocal root of the calculation according to the selected calculation mode, and determines the selector 5 corresponding to the reciprocal root of the calculation from the selector 3, the selector 4, and the selector 5. If E i of the floating point number is odd and the value of M 0 is 0, then 381 in selector 5 is selected and output to adder 1, and adder 1 outputs E′ i =381-E i to selector 6, if floating If the E i of the point is odd and the value of M 0 is not 0, select 379 in selector 5 and output it to adder 1, and adder 1 outputs E′ i =379-E i to selector 6, if the floating point number If E i is an even number, select 380 in selector 5 and output to adder 1, and adder 1 outputs E′ i =380-E i to selector 6.
选择器7根据选择的计算模式为计算开方倒数,选择-(t n<<1),为浮点数中尾数数据段的低位子数据段(t n)赋予
Figure PCTCN2019108872-appb-000084
的系数,并输出给加法器2,同时浮点数中尾数数据段的高位子数据段(a n)输入至加法器2中,加法器2输出
Figure PCTCN2019108872-appb-000085
给乘法器1。另外,从存储的预设数值表中,获取计算开方对应的预设数值表,根据浮点数中的a n,从预设数值表中获取
Figure PCTCN2019108872-appb-000086
的值并输出给乘法器1。
The selector 7 calculates the reciprocal square root according to the selected calculation mode, and selects -(t n <<1) to assign the lower sub-data segment (t n ) of the mantissa data segment in the floating-point number
Figure PCTCN2019108872-appb-000084
And output to adder 2. At the same time, the high-order sub-data segment (a n ) of the mantissa data segment in the floating-point number is input to adder 2, and adder 2 outputs
Figure PCTCN2019108872-appb-000085
Give the multiplier 1. In addition, obtain the preset value table corresponding to the square root from the stored preset value table, and obtain it from the preset value table according to the a n in the floating point number
Figure PCTCN2019108872-appb-000086
And output to the multiplier 1.
第二阶段,选择器6根据选择的计算模式为计算开方,选择E′ i>>1为E′ i赋予系数
Figure PCTCN2019108872-appb-000087
获得
Figure PCTCN2019108872-appb-000088
并输出给寄存器1。乘法器1将
Figure PCTCN2019108872-appb-000089
Figure PCTCN2019108872-appb-000090
相乘,获得
Figure PCTCN2019108872-appb-000091
的值与
Figure PCTCN2019108872-appb-000092
的值的乘积,该乘积例如为48bit,确定该48bit的乘积中第一个1的位置,从该位的下一位开始从高位到低位的顺序取23bit,即获得24bit,并将该24位存入寄存器2以及还将该24位输出给乘法器2。
In the second stage, the selector 6 calculates the square root according to the selected calculation mode, and selects E′ i >>1 to assign coefficients to E′ i
Figure PCTCN2019108872-appb-000087
obtain
Figure PCTCN2019108872-appb-000088
And output to register 1. Multiplier 1 will
Figure PCTCN2019108872-appb-000089
versus
Figure PCTCN2019108872-appb-000090
Multiply to get
Figure PCTCN2019108872-appb-000091
And the value of
Figure PCTCN2019108872-appb-000092
The product of the value of, the product is 48bit, for example, determine the position of the first 1 in the product of 48bit, and take 23bit from the next bit of the bit from high to low, that is, 24bit is obtained, and the 24bit Store in register 2 and output the 24 bits to multiplier 2.
第三阶段,乘法器2对输入的24位的数值乘
Figure PCTCN2019108872-appb-000093
输出48比特的乘积,然后确定该48bit的乘积中第一个1的位置,从该位的下一位开始从高位到低位的顺序取23bit,即获得24bit。如果E i为偶数,选择器8选择从寄存器2中获取该24bit的值并输出,以获得M 0,如果E i为奇数,选择器8选择通过乘法器2获得的24bit的值并输出,以获得M 0。另外,获取寄存器1中存储的E 0并输出。同时,选择器9根据选择的计算模式为计算开方倒数,选择输出S 0=0。
In the third stage, the multiplier 2 multiplies the input 24-bit value
Figure PCTCN2019108872-appb-000093
Output a 48-bit product, and then determine the position of the first 1 in the 48-bit product. From the next bit of the bit, take 23 bits from high to low to obtain 24 bits. If E i is an even number, selector 8 chooses to obtain the 24-bit value from register 2 and output it to obtain M 0 , if E i is an odd number, selector 8 selects the 24-bit value obtained through multiplier 2 and outputs it, Obtain M 0 . In addition, the E 0 stored in the register 1 is obtained and output. At the same time, the selector 9 calculates the reciprocal root of the calculation according to the selected calculation mode, and selects the output S 0 =0.
在第三阶段计算S 0,以及将E 0暂时存储在寄存器,可以保证运算结果中S 0、E 0、M 0的时序同步。而且,本实现方式中的第一运算公式为
Figure PCTCN2019108872-appb-000094
可以使 得第三阶段的硬件与计算开方时第三阶段的硬件相同,节省了硬件成本。
Calculating S 0 in the third stage and temporarily storing E 0 in the register can ensure that the timing of S 0 , E 0 , and M 0 in the operation result is synchronized. Moreover, the first calculation formula in this implementation is
Figure PCTCN2019108872-appb-000094
The hardware of the third stage can be made the same as the hardware of the third stage when calculating the prescription, which saves the hardware cost.
在另一种可能的实现方式中,上述的第一运算公式可以设为
Figure PCTCN2019108872-appb-000095
上述加法运算公式为
Figure PCTCN2019108872-appb-000096
根据k的不同取值,计算
Figure PCTCN2019108872-appb-000097
从而预先获得对应计算开方倒数的预设数值表并存储,其中k由m0至m8确定。当需要计算
Figure PCTCN2019108872-appb-000098
时,根据预先存储的m0至m8与
Figure PCTCN2019108872-appb-000099
的对应关系的预设数值表,获取对应的
Figure PCTCN2019108872-appb-000100
的值,并通过上述加法运算单元获取
Figure PCTCN2019108872-appb-000101
的值,再将通过第一乘法器获得
Figure PCTCN2019108872-appb-000102
的值与
Figure PCTCN2019108872-appb-000103
的值的乘积,该乘积为48bit。
In another possible implementation manner, the above-mentioned first calculation formula can be set as
Figure PCTCN2019108872-appb-000095
The above addition formula is
Figure PCTCN2019108872-appb-000096
According to the different values of k, calculate
Figure PCTCN2019108872-appb-000097
Thereby, a preset numerical table corresponding to the reciprocal root of the calculation is obtained in advance and stored, where k is determined by m0 to m8. When need to calculate
Figure PCTCN2019108872-appb-000098
, According to the pre-stored m0 to m8 and
Figure PCTCN2019108872-appb-000099
The corresponding preset value table of the corresponding relationship to obtain the corresponding
Figure PCTCN2019108872-appb-000100
The value of and is obtained by the above addition operation unit
Figure PCTCN2019108872-appb-000101
The value of will be obtained through the first multiplier
Figure PCTCN2019108872-appb-000102
And the value of
Figure PCTCN2019108872-appb-000103
The product of the values, the product is 48bit.
如果E i为奇数,则以通过第一乘法器获得的乘积中第一个1的位置为MSB由高到低的顺序取24bit,再通过第二乘法器与2相乘,获得48bit的乘积,并确定通过第二乘法器获得的乘积中第一个1的位置,该位作为M 0的隐含位,从该位的下一位开始从高位到低位的顺序取23bit作为M 0。如果E i为偶数,则以通过第一乘法器获得的乘积中第一个1的位置为MSB由高到低的顺序取24bit,再通过第三乘法器与
Figure PCTCN2019108872-appb-000104
相乘,获得48bit的乘积,并确定通过第三乘法器获得的乘积中第一个1的位置,该位作为M 0的隐含位,从该位的下一位开始从高位到低位的顺序取23bit作为M 0
If E i is an odd number, take the position of the first 1 in the product obtained by the first multiplier and take 24 bits in the order of MSB from high to low, and then multiply by 2 through the second multiplier to obtain a 48-bit product. And determine the position of the first 1 in the product obtained by the second multiplier. This bit is used as the hidden bit of M 0 , and 23 bits are taken as M 0 in the order from the next bit to the low bit. If E i is an even number, the position of the first 1 in the product obtained by the first multiplier is taken from high to low in order of 24 bits, and then through the third multiplier and
Figure PCTCN2019108872-appb-000104
Multiply to obtain a 48-bit product, and determine the position of the first 1 in the product obtained by the third multiplier. This bit is used as the hidden bit of M 0 , starting from the next bit in the order from high to low Take 23bit as M 0 .
在另一种可能的实现方式中,计算开方倒数的预设数值表为两个,分别为第一预设数值表和第二预设数值表,第一预设数值表对应E i为偶数,则第一预设数值表对应的上述的第一运算公式可以设为
Figure PCTCN2019108872-appb-000105
第二预设数值表对应E i为奇数,则第二预设数值表对应的上述的第一运算公式可以设为
Figure PCTCN2019108872-appb-000106
上述加法运算公式为
Figure PCTCN2019108872-appb-000107
根据k的不同取值,计算
Figure PCTCN2019108872-appb-000108
从而预先获得对应计算开方倒数的第一预设数值表并存储,另外,还根据k的不同取值,计算
Figure PCTCN2019108872-appb-000109
从而预先获得对应计算开方倒数的第二预设数值表并存储,其中k由m0至m8确定。当需要计算
Figure PCTCN2019108872-appb-000110
时,如果E i为偶数,则根据预先存储的m0至m8与
Figure PCTCN2019108872-appb-000111
的对应关系的第一预设数值表,获取对应的
Figure PCTCN2019108872-appb-000112
的值,并通过上述加法运算单元获取
Figure PCTCN2019108872-appb-000113
的值,再将通过乘法器获得
Figure PCTCN2019108872-appb-000114
的值与
Figure PCTCN2019108872-appb-000115
的值的乘积,该乘积为48bit,并确定该48bit的乘积中第一 个1的位置,该位作为M 0的隐含位,从该位的下一位开始从高位到低位的顺序取23bit作为M 0。如果E i为奇数,则根据预先存储的m0至m8与
Figure PCTCN2019108872-appb-000116
的对应关系的第二预设数值表,获取对应的
Figure PCTCN2019108872-appb-000117
的值,并通过上述加法运算单元获取
Figure PCTCN2019108872-appb-000118
的值,再将通过乘法器获得
Figure PCTCN2019108872-appb-000119
的值与
Figure PCTCN2019108872-appb-000120
的值的乘积,该乘积为48bit,并确定该48bit的乘积中第一个1的位置,该位作为M 0的隐含位,从该位的下一位开始从高位到低位的顺序取23bit作为M 0
In another possible implementation, there are two preset value tables for calculating the reciprocal root of the square, namely the first preset value table and the second preset value table, and the first preset value table corresponds to E i as an even number. , Then the above-mentioned first calculation formula corresponding to the first preset value table can be set as
Figure PCTCN2019108872-appb-000105
The second preset value table corresponding to E i is odd, then the above-mentioned first calculation formula corresponding to the second preset value table can be set as
Figure PCTCN2019108872-appb-000106
The above addition formula is
Figure PCTCN2019108872-appb-000107
According to the different values of k, calculate
Figure PCTCN2019108872-appb-000108
In this way, the first preset value table corresponding to the reciprocal root of the calculation is obtained in advance and stored. In addition, according to the different values of k, the calculation
Figure PCTCN2019108872-appb-000109
Thereby, a second preset value table corresponding to the reciprocal root of the calculation is obtained in advance and stored, where k is determined by m0 to m8. When need to calculate
Figure PCTCN2019108872-appb-000110
, If E i is an even number, according to the pre-stored m0 to m8 and
Figure PCTCN2019108872-appb-000111
The first preset value table of the corresponding relationship to obtain the corresponding
Figure PCTCN2019108872-appb-000112
The value of and is obtained by the above addition operation unit
Figure PCTCN2019108872-appb-000113
The value of will be obtained through the multiplier
Figure PCTCN2019108872-appb-000114
And the value of
Figure PCTCN2019108872-appb-000115
The product of the value of, the product is 48bit, and the position of the first 1 in the product of the 48bit is determined. This bit is used as the implicit bit of M 0 , and 23bit is taken from the next bit to the low bit in order from the next bit. As M 0 . If E i is an odd number, according to the pre-stored m0 to m8 and
Figure PCTCN2019108872-appb-000116
The second preset value table of the corresponding relationship to obtain the corresponding
Figure PCTCN2019108872-appb-000117
The value of and is obtained by the above addition operation unit
Figure PCTCN2019108872-appb-000118
The value of will be obtained through the multiplier
Figure PCTCN2019108872-appb-000119
And the value of
Figure PCTCN2019108872-appb-000120
The product of the value of, the product is 48bit, and the position of the first 1 in the product of the 48bit is determined. This bit is used as the implicit bit of M 0 , and 23bit is taken from the next bit to the low bit in order from the next bit. As M 0 .
因此,本实施例存储有与
Figure PCTCN2019108872-appb-000121
有关的运算结果的预设数据表,通过查表和简单的加法、乘法运算来获得浮点数的开方倒数,由于本实施例只存储尾数数据段中高位子数据段的运算结果,降低了预设数据表的存储量,降低了硬件成本,还提高了运算效率。
Therefore, this embodiment stores and
Figure PCTCN2019108872-appb-000121
The preset data table of the related operation result is obtained by looking up the table and simple addition and multiplication operations to obtain the reciprocal root of the floating-point number. Since this embodiment only stores the operation result of the upper sub-data segment in the mantissa data segment, the preset value is reduced. The storage capacity of the data table reduces the hardware cost and also improves the computing efficiency.
需要说明的是,各个计算模式下计算浮点数的精度可以根据泰勒展开的余项的位数确定,余项可以通过t n表示。例如,可以根据余项的位数,确定对尾数数据段划分得到的a n的位数以及t n的位数。划分得到的a n的位数越多,相应的t n的位数越少,因而t n对应的余项的位数也就越少。因此,通过调整划分后的a n的位数和t n的位数,可以调整浮点数的运算结果的精度。值得注意的是,a n的位数较多,相应的a n可能的取值范围越大(例如a n的位数为9,a n的取值范围为[0,512)),那么对应a n的预设数据表的存储量会增大,查表的数据量会加大。所以,在一些实施方式中,也可以通过适当的调整a n的位数与t n的位数,会牺牲一些运算量来提升精度。 It should be noted that the accuracy of calculating floating-point numbers in each calculation mode can be determined according to the number of bits of the remainder of Taylor expansion, and the remainder can be represented by t n. For example, the number of bits of the remainder, determining the number of bits of the mantissa section data obtained by dividing a n t n and the number of bits. The more the number of bits obtained by dividing a n, the less the number of bits corresponding to t n, t and thus the number of bits n corresponding to the remainder of the fewer. Thus, a number of bits by dividing the adjusted and a n t n, the result may be adjusted precision floating-point arithmetic. Notably, the more bits a n, a n corresponding greater range of possible values (e.g., number of bits. 9 is a n, a n is in the range [0, 512)), then the corresponding a n The storage capacity of the preset data table will increase, and the data quantity of the look-up table will increase. Therefore, in some embodiments, the number of bits can be appropriately adjusted with a n t n bits by, sacrifice some amount of computation to improve accuracy.
图6为本申请一实施例提供的浮点数处理设备的结构示意图,如图6所示,本实施例的浮点数处理设备600可以包括:处理器601、加法运算单元602、第一乘法器603、第一存储装置604和第二存储装置605。可选地,第一存储装置604和第二存储装置605可以是同一存储装置,也可以是不同的存储装置。可选地,浮点数处理设备600还可以包括第二乘法器606。6 is a schematic structural diagram of a floating-point number processing device provided by an embodiment of the application. As shown in FIG. 6, the floating-point number processing device 600 of this embodiment may include: a processor 601, an addition unit 602, and a first multiplier 603 , The first storage device 604 and the second storage device 605. Optionally, the first storage device 604 and the second storage device 605 may be the same storage device or different storage devices. Optionally, the floating-point number processing device 600 may further include a second multiplier 606.
所述第一存储装置604,用于存储浮点数以及浮点数在计算模式下的运算结果;The first storage device 604 is configured to store floating-point numbers and calculation results of floating-point numbers in calculation mode;
所述第二存储装置605,用于存储不同计算模式分别对应的预设数值表;The second storage device 605 is configured to store preset value tables corresponding to different calculation modes respectively;
所述处理器601,用于:The processor 601 is configured to:
获取浮点数的处理指令,所述处理指令用于指示浮点数的计算模式,所述浮点数包括尾数数据段;Acquiring a processing instruction of a floating-point number, the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
在所述尾数数据段的存储地址,从所述第一存储装置604中分别读取所述尾数数据段的高位子数据段和低位子数据段;At the storage address of the mantissa data segment, read the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment from the first storage device 604;
根据所述高位子数据段的数值,在所述第二存储装置605存储的对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;According to the value of the high-order sub-data segment, the first value is obtained by looking up the preset value table corresponding to the calculation mode stored in the second storage device 605, and the preset value table includes the high-order sub-data segment The corresponding relationship between the value of and the result calculated by the first calculation formula;
将所述高位子数据段的数值和低位子数据段的数值输入所述加法运算单元602,以使所述加法运算单元602根据对应所述计算模式的加法运算公式执行运算,得到第二值;Input the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment into the addition unit 602, so that the addition unit 602 performs an operation according to the addition operation formula corresponding to the calculation mode to obtain a second value;
将所述第一值和所述加法运算单元602计算得到的所述第二值输入第一乘法器603,得到第一乘积结果;Input the first value and the second value calculated by the addition unit 602 into the first multiplier 603 to obtain a first product result;
根据所述第一乘法器603得到的所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值并且存入所述第一存储装置604中对应所述浮点数在所述计算模式下的运算结果的尾数数据段地址;According to the first product result obtained by the first multiplier 603, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 604 corresponding to the The address of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。Wherein, the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
在一些实施例中,所述加法运算单元602包括选择器6021和加法器6022,所述处理器601,具体用于:In some embodiments, the addition unit 602 includes a selector 6021 and an adder 6022, and the processor 601 is specifically configured to:
将所述低位子数据段的数值输入所述选择器,以使所述选择器6021为所述低位子数据段的数值赋予与所述计算模式对应的运算系数,获得第三值;Input the numerical value of the low-order sub-data segment to the selector, so that the selector 6021 assigns the numerical value of the low-order sub-data segment to the calculation coefficient corresponding to the calculation mode to obtain a third value;
将所述高位子数据段的数值和所述第三值输入所述加法器6022,得到所述第二值。The numerical value of the high-order sub-data segment and the third value are input to the adder 6022 to obtain the second value.
在一些实施例中,所述高位子数据段的位数与所述低位子数据位的位数之和等于所述尾数数据段的位数。In some embodiments, the sum of the number of bits in the upper sub-data segment and the number of lower sub-data bits is equal to the number of bits in the mantissa data segment.
在一些实施例中,所述高位子数据段的位数与所述尾数数据段的位数,根据对应所述泰勒展开的余项部分的精度确定。In some embodiments, the number of bits in the upper sub-data segment and the number of bits in the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion.
在一些实施例中,所述计算模式包括计算倒数、计算开方、计算开方倒数。In some embodiments, the calculation mode includes calculating the reciprocal, calculating the square root, and calculating the reciprocal square root.
在一些实施例中,若所述计算模式包括计算倒数,则所述第一运算公式为
Figure PCTCN2019108872-appb-000122
所述加法运算公式为a+(-1)t;
In some embodiments, if the calculation mode includes calculating the reciprocal, the first calculation formula is
Figure PCTCN2019108872-appb-000122
The addition operation formula is a+(-1)t;
若所述计算模式包括计算开方,则所述第一运算公式为
Figure PCTCN2019108872-appb-000123
所述加法 运算公式为
Figure PCTCN2019108872-appb-000124
If the calculation mode includes a square root, the first calculation formula is
Figure PCTCN2019108872-appb-000123
The addition operation formula is
Figure PCTCN2019108872-appb-000124
若所述计算模式包括计算开方倒数,则所述第一运算公式为
Figure PCTCN2019108872-appb-000125
所述加法运算公式为
Figure PCTCN2019108872-appb-000126
If the calculation mode includes calculating the reciprocal root, the first calculation formula is
Figure PCTCN2019108872-appb-000125
The addition operation formula is
Figure PCTCN2019108872-appb-000126
其中,a为所述高位子数据段的数值,t为所述低位子数据段的数值。Wherein, a is the value of the upper sub-data segment, and t is the value of the lower sub-data segment.
在一些实施例中,所述处理器601,具体用于:In some embodiments, the processor 601 is specifically configured to:
获取所述第一乘积结果中第一预设数值之后的预设位数的数值;Acquiring the value of the preset number of digits after the first preset value in the first product result;
根据所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;Obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the value of the preset number of digits;
其中,所述预设位数为所述尾数数据段的位数。Wherein, the preset number of bits is the number of bits of the mantissa data segment.
在一些实施例中,所述处理器601,具体用于:In some embodiments, the processor 601 is specifically configured to:
若所述计算模式包括计算倒数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the reciprocal calculation, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述浮点数还包括:指数数据段;所述处理器601,具体用于:In some embodiments, the floating point number further includes: an exponent data segment; and the processor 601 is specifically configured to:
若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the preset number of bits The value of the mantissa data segment of the result.
在一些实施例中,所述计算模式包括计算开方,所述处理器601,具体用于:In some embodiments, the calculation mode includes calculating a square root, and the processor 601 is specifically configured to:
若所述指数数据段的数值为奇数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an odd number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为偶数,则将所述预设位数的数值以及第二预设数值输入第二乘法器606,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an even number, the value of the preset number of digits and the second preset value are input to the second multiplier 606 to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述计算模式包括计算开方倒数,所述处理器601,具体用于:In some embodiments, the calculation mode includes calculating the reciprocal root, and the processor 601 is specifically configured to:
若所述指数数据段的数值为偶数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an even number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为奇数,则将所述预设位数的数值以及第二预 设数值输入第二乘法器606,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an odd number, the value of the preset number of bits and the second preset value are input to the second multiplier 606 to obtain a second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述浮点数包括符号数据段;所述处理器601,还用于:In some embodiments, the floating-point number includes a symbol data segment; the processor 601 is further configured to:
在所述符号数据段的存储地址,从所述第一存储装置604读取所述符号数据段的数值;At the storage address of the symbol data segment, read the value of the symbol data segment from the first storage device 604;
根据所述符号数据段的数值,获得所述浮点数在所述计算模式下的运算结果的符号数据段的数值并且存入所述第一存储装置604中对应所述浮点数在所述计算模式下的运算结果的符号数据段地址。According to the value of the symbol data segment, the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 604 corresponding to the floating-point number in the calculation mode The symbol data segment address of the operation result below.
在一些实施例中,所述处理器601,具体用于:In some embodiments, the processor 601 is specifically configured to:
若所述计算模式包括计算倒数,则将所述符号数据段的数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值;If the calculation mode includes a reciprocal calculation, use the value of the symbol data segment as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode;
若所述计算模式包括计算开方或者计算开方倒数,则将第三预设数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the third preset value is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述浮点数包括指数数据段;所述处理器601,还用于:In some embodiments, the floating point number includes an exponent data segment; the processor 601 is further configured to:
在所述指数数据段的存储地址,从所述第一存储装置604读取所述指数数据段的数值;At the storage address of the index data segment, read the value of the index data segment from the first storage device 604;
根据所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值并且存入所述第一存储装置604中对应所述浮点数在所述计算模式下的运算结果的指数数据段地址。According to the value of the exponent data segment, the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 604 corresponding to the floating-point number in the calculation mode The address of the exponent data segment of the operation result under.
在一些实施例中,所述处理器601,具体用于:In some embodiments, the processor 601 is specifically configured to:
若所述计算模式包括计算倒数,则根据所述尾数数据段的数值以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值;If the calculation mode includes the reciprocal calculation, obtain the value of the exponent data segment of the operation result of the floating-point number in the calculation mode according to the value of the mantissa data segment and the value of the exponent data segment;
若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
在一些实施例中,所述计算模式包括计算倒数,所述处理器601,具体 用于:In some embodiments, the calculation mode includes calculating the reciprocal, and the processor 601 is specifically configured to:
若所述尾数数据段的数值为第三预设值,则将254-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is the third preset value, use the value of 254-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
若所述尾数数据段的数值不为第三预设值,则将253-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is not the third preset value, use the value of 253-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
在一些实施例中,所述计算模式包括计算开方,所述处理器601,具体用于:In some embodiments, the calculation mode includes calculating a square root, and the processor 601 is specifically configured to:
若所述指数数据段的数值为奇数,则将
Figure PCTCN2019108872-appb-000127
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an odd number, then
Figure PCTCN2019108872-appb-000127
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为偶数,则将
Figure PCTCN2019108872-appb-000128
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an even number, then
Figure PCTCN2019108872-appb-000128
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
在一些实施例中,所述计算模式包括计算开方倒数,所述处理器601,具体用于:In some embodiments, the calculation mode includes calculating the reciprocal root, and the processor 601 is specifically configured to:
若所述指数数据段的数值为奇数且所述尾数数据段的数值不等于第三预设数值,则将
Figure PCTCN2019108872-appb-000129
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is odd and the value of the mantissa data segment is not equal to the third preset value, then
Figure PCTCN2019108872-appb-000129
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为奇数且所述尾数数据段的数值等于第三预设数值,则将
Figure PCTCN2019108872-appb-000130
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then
Figure PCTCN2019108872-appb-000130
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为偶数,则将
Figure PCTCN2019108872-appb-000131
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an even number, then
Figure PCTCN2019108872-appb-000131
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
可选地,本实施例的浮点数处理设备600还可以包括:用于存储程序代码的存储器(图中未示出),存储器用于存储程序代码,当程序代码被执行时,所述浮点数处理设备600可以实现上述的技术方案。Optionally, the floating-point number processing device 600 of this embodiment may further include: a memory (not shown in the figure) for storing program codes. The memory is used for storing program codes. When the program codes are executed, the floating-point number The processing device 600 can implement the above-mentioned technical solutions.
本实施例的浮点数处理设备,可以用于执行图2及对应方法实施例的技术方案,其实现原理和技术效果类似,此处不再赘述。The floating-point number processing device of this embodiment can be used to implement the technical solutions of FIG. 2 and the corresponding method embodiment, and its implementation principles and technical effects are similar, and will not be repeated here.
图7为本申请一实施例提供的可移动平台的结构示意图,如图7所示,本实施例的可移动平台700可以包括:处理器701、加法运算单元702、第一 乘法器703、第一存储装置704和第二存储装置705。可选地,第一存储装置704和第二存储装置705可以是同一存储装置,也可以是不同的存储装置。可选地,可移动平台700还可以包括第二乘法器706。FIG. 7 is a schematic structural diagram of a movable platform provided by an embodiment of the application. As shown in FIG. 7, the movable platform 700 of this embodiment may include: a processor 701, an addition unit 702, a first multiplier 703, and a first multiplier 703. A storage device 704 and a second storage device 705. Optionally, the first storage device 704 and the second storage device 705 may be the same storage device or different storage devices. Optionally, the movable platform 700 may further include a second multiplier 706.
所述第一存储装置704,用于存储浮点数以及浮点数在计算模式下的运算结果;The first storage device 704 is configured to store floating-point numbers and calculation results of floating-point numbers in calculation mode;
所述第二存储装置705,用于存储不同计算模式分别对应的预设数值表;The second storage device 705 is configured to store preset value tables corresponding to different calculation modes, respectively;
所述处理器701,用于:The processor 701 is configured to:
获取浮点数的处理指令,所述处理指令用于指示浮点数的计算模式,所述浮点数包括尾数数据段;Acquiring a processing instruction of a floating-point number, the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
在所述尾数数据段的存储地址,从所述第一存储装置704中分别读取所述尾数数据段的高位子数据段和低位子数据段;At the storage address of the mantissa data segment, read the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment from the first storage device 704, respectively;
根据所述高位子数据段的数值,在所述第二存储装置705存储的对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;According to the value of the high-order sub-data segment, the first value is obtained by looking up a preset value table corresponding to the calculation mode stored in the second storage device 705, and the preset value table includes the high-order sub-data segment The corresponding relationship between the value of and the result calculated by the first calculation formula;
将所述高位子数据段的数值和低位子数据段的数值输入所述加法运算单元702,以使所述加法运算单元702根据对应所述计算模式的加法运算公式执行运算,得到第二值;Input the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment into the addition unit 702, so that the addition unit 702 performs an operation according to the addition operation formula corresponding to the calculation mode to obtain a second value;
将所述第一值和所述加法运算单元702计算得到的所述第二值输入第一乘法器703,得到第一乘积结果;Input the first value and the second value calculated by the addition unit 702 into a first multiplier 703 to obtain a first product result;
根据所述第一乘法器703得到的所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值并且存入所述第一存储装置704中对应所述浮点数在所述计算模式下的运算结果的尾数数据段地址;According to the first product result obtained by the first multiplier 703, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 704. The address of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。Wherein, the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
在一些实施例中,所述加法运算单元702包括选择器7021和加法器7022,所述处理器701,具体用于:In some embodiments, the addition unit 702 includes a selector 7021 and an adder 7022, and the processor 701 is specifically configured to:
将所述低位子数据段的数值输入所述选择器,以使所述选择器7021为所述低位子数据段的数值赋予与所述计算模式对应的运算系数,获得第三值;Inputting the numerical value of the low-order sub-data segment to the selector, so that the selector 7021 assigns the numerical value of the low-order sub-data segment to the calculation coefficient corresponding to the calculation mode to obtain a third value;
将所述高位子数据段的数值和所述第三值输入所述加法器7022,得到所述第二值。The numerical value of the high-order sub-data segment and the third value are input to the adder 7022 to obtain the second value.
在一些实施例中,所述高位子数据段的位数与所述低位子数据位的位数之和等于所述尾数数据段的位数。In some embodiments, the sum of the number of bits in the upper sub-data segment and the number of lower sub-data bits is equal to the number of bits in the mantissa data segment.
在一些实施例中,所述高位子数据段的位数与所述尾数数据段的位数,根据对应所述泰勒展开的余项部分的精度确定。In some embodiments, the number of bits in the upper sub-data segment and the number of bits in the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion.
在一些实施例中,所述计算模式包括计算倒数、计算开方、计算开方倒数。In some embodiments, the calculation mode includes calculating the reciprocal, calculating the square root, and calculating the reciprocal square root.
在一些实施例中,若所述计算模式包括计算倒数,则所述第一运算公式为
Figure PCTCN2019108872-appb-000132
所述加法运算公式为a+(-1)t;
In some embodiments, if the calculation mode includes calculating the reciprocal, the first calculation formula is
Figure PCTCN2019108872-appb-000132
The addition operation formula is a+(-1)t;
若所述计算模式包括计算开方,则所述第一运算公式为
Figure PCTCN2019108872-appb-000133
所述加法运算公式为
Figure PCTCN2019108872-appb-000134
If the calculation mode includes a square root, the first calculation formula is
Figure PCTCN2019108872-appb-000133
The addition operation formula is
Figure PCTCN2019108872-appb-000134
若所述计算模式包括计算开方倒数,则所述第一运算公式为
Figure PCTCN2019108872-appb-000135
所述加法运算公式为
Figure PCTCN2019108872-appb-000136
If the calculation mode includes calculating the reciprocal root, the first calculation formula is
Figure PCTCN2019108872-appb-000135
The addition operation formula is
Figure PCTCN2019108872-appb-000136
其中,a为所述高位子数据段的数值,t为所述低位子数据段的数值。Wherein, a is the value of the upper sub-data segment, and t is the value of the lower sub-data segment.
在一些实施例中,所述处理器701,具体用于:In some embodiments, the processor 701 is specifically configured to:
获取所述第一乘积结果中第一预设数值之后的预设位数的数值;Acquiring the value of the preset number of digits after the first preset value in the first product result;
根据所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;Obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the value of the preset number of digits;
其中,所述预设位数为所述尾数数据段的位数。Wherein, the preset number of bits is the number of bits of the mantissa data segment.
在一些实施例中,所述处理器701,具体用于:In some embodiments, the processor 701 is specifically configured to:
若所述计算模式包括计算倒数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the reciprocal calculation, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述浮点数还包括:指数数据段;所述处理器701,具体用于:In some embodiments, the floating point number further includes: an exponent data segment; and the processor 701 is specifically configured to:
若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the preset number of bits The value of the mantissa data segment of the result.
在一些实施例中,所述计算模式包括计算开方,所述处理器701,具体用于:In some embodiments, the calculation mode includes calculating a square root, and the processor 701 is specifically configured to:
若所述指数数据段的数值为奇数,则将所述预设位数的数值作为所述浮 点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an odd number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating point number in the calculation mode;
若所述指数数据段的数值为偶数,则将所述预设位数的数值以及第二预设数值输入第二乘法器706,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an even number, the value of the preset number of digits and the second preset value are input to the second multiplier 706 to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述计算模式包括计算开方倒数,所述处理器701,具体用于:In some embodiments, the calculation mode includes calculating the reciprocal root, and the processor 701 is specifically configured to:
若所述指数数据段的数值为偶数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an even number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为奇数,则将所述预设位数的数值以及第二预设数值输入第二乘法器706,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an odd number, the value of the preset number of bits and the second preset value are input to the second multiplier 706 to obtain a second multiplication result, and the second multiplication result is obtained The value of the preset number of digits after the first preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述浮点数包括符号数据段;所述处理器701,还用于:In some embodiments, the floating-point number includes a symbol data segment; the processor 701 is further configured to:
在所述符号数据段的存储地址,从所述第一存储装置704读取所述符号数据段的数值;At the storage address of the symbol data segment, read the value of the symbol data segment from the first storage device 704;
根据所述符号数据段的数值,获得所述浮点数在所述计算模式下的运算结果的符号数据段的数值并且存入所述第一存储装置704中对应所述浮点数在所述计算模式下的运算结果的符号数据段地址。According to the value of the symbol data segment, the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 704 corresponding to the floating-point number in the calculation mode The symbol data segment address of the operation result below.
在一些实施例中,所述处理器701,具体用于:In some embodiments, the processor 701 is specifically configured to:
若所述计算模式包括计算倒数,则将所述符号数据段的数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值;If the calculation mode includes a reciprocal calculation, use the value of the symbol data segment as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode;
若所述计算模式包括计算开方或者计算开方倒数,则将第三预设数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the third preset value is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
在一些实施例中,所述浮点数包括指数数据段;所述处理器701,还用于:In some embodiments, the floating point number includes an exponent data segment; the processor 701 is further configured to:
在所述指数数据段的存储地址,从所述第一存储装置704读取所述指数数据段的数值;At the storage address of the index data segment, read the value of the index data segment from the first storage device 704;
根据所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算 结果的指数数据段的数值并且存入所述第一存储装置704中对应所述浮点数在所述计算模式下的运算结果的指数数据段地址。According to the value of the exponent data segment, the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device 704 corresponding to the floating-point number in the calculation mode The address of the exponent data segment of the operation result under.
在一些实施例中,所述处理器701,具体用于:In some embodiments, the processor 701 is specifically configured to:
若所述计算模式包括计算倒数,则根据所述尾数数据段的数值以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值;If the calculation mode includes the reciprocal calculation, obtain the value of the exponent data segment of the operation result of the floating-point number in the calculation mode according to the value of the mantissa data segment and the value of the exponent data segment;
若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
在一些实施例中,所述计算模式包括计算倒数,所述处理器701,具体用于:In some embodiments, the calculation mode includes calculating the reciprocal, and the processor 701 is specifically configured to:
若所述尾数数据段的数值为第三预设值,则将254-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is the third preset value, use the value of 254-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
若所述尾数数据段的数值不为第三预设值,则将253-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is not the third preset value, use the value of 253-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
在一些实施例中,所述计算模式包括计算开方,所述处理器701,具体用于:In some embodiments, the calculation mode includes calculating a square root, and the processor 701 is specifically configured to:
若所述指数数据段的数值为奇数,则将
Figure PCTCN2019108872-appb-000137
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an odd number, then
Figure PCTCN2019108872-appb-000137
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为偶数,则将
Figure PCTCN2019108872-appb-000138
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an even number, then
Figure PCTCN2019108872-appb-000138
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
在一些实施例中,所述计算模式包括计算开方倒数,所述处理器701,具体用于:In some embodiments, the calculation mode includes calculating the reciprocal root, and the processor 701 is specifically configured to:
若所述指数数据段的数值为奇数且所述尾数数据段的数值不等于第三预设数值,则将
Figure PCTCN2019108872-appb-000139
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is odd and the value of the mantissa data segment is not equal to the third preset value, then
Figure PCTCN2019108872-appb-000139
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为奇数且所述尾数数据段的数值等于第三预设数值,则将
Figure PCTCN2019108872-appb-000140
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then
Figure PCTCN2019108872-appb-000140
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
若所述指数数据段的数值为偶数,则将
Figure PCTCN2019108872-appb-000141
确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
If the value of the exponent data segment is an even number, then
Figure PCTCN2019108872-appb-000141
The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
可选地,本实施例的可移动平台700还可以包括:用于存储程序代码的存储器(图中未示出),存储器用于存储程序代码,当程序代码被执行时,所述可移动平台700可以实现上述的技术方案。Optionally, the movable platform 700 of this embodiment may further include: a memory (not shown in the figure) for storing program codes, the memory is used for storing program codes, and when the program codes are executed, the movable platform 700 can implement the above-mentioned technical solutions.
本实施例的可移动平台,可以用于执行图2及对应方法实施例的技术方案,其实现原理和技术效果类似,此处不再赘述。The movable platform of this embodiment can be used to implement the technical solutions of FIG. 2 and the corresponding method embodiments, and its implementation principles and technical effects are similar, and will not be repeated here.
图8为本申请另一实施例提供的可移动平台的结构示意图,如图8所示,本实施例的可移动平台800可以包括:可移动平台本体801以及浮点数处理设备802。FIG. 8 is a schematic structural diagram of a movable platform provided by another embodiment of this application. As shown in FIG. 8, the movable platform 800 of this embodiment may include: a movable platform body 801 and a floating-point number processing device 802.
其中,所述浮点数处理设备802安装于所述可移动平台本体801上。浮点数处理设备802可以是独立于可移动平台本体801的设备。Wherein, the floating-point number processing device 802 is installed on the movable platform body 801. The floating-point number processing device 802 may be a device independent of the movable platform body 801.
其中,浮点数处理设备802可以采用图6所示装置实施例的结构,其对应地,可以执行图2及其对应方法实施例的技术方案,其实现原理和技术效果类似,此处不再赘述。Among them, the floating-point number processing device 802 can adopt the structure of the device embodiment shown in FIG. 6, and it can correspondingly execute the technical solutions of the embodiment of FIG. 2 and its corresponding method. Its implementation principles and technical effects are similar, and will not be repeated here. .
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:只读内存(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。A person of ordinary skill in the art can understand that all or part of the steps in the above method embodiments can be implemented by a program instructing relevant hardware. The foregoing program can be stored in a computer readable storage medium. When the program is executed, it is executed. Including the steps of the foregoing method embodiment; and the foregoing storage medium includes: read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disks or optical disks, etc., which can store program codes Medium.
最后应说明的是:以上各实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述各实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the application, not to limit them; although the application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: It is still possible to modify the technical solutions described in the foregoing embodiments, or equivalently replace some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the technical solutions of the embodiments of the present application. range.

Claims (39)

  1. 一种浮点数处理方法,其特征在于,包括:A floating-point number processing method, characterized in that it comprises:
    获取浮点数的处理指令,所述处理指令用于指示浮点数的计算模式,所述浮点数包括尾数数据段;Acquiring a processing instruction of a floating-point number, the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
    在所述尾数数据段的存储地址,分别读取所述尾数数据段的高位子数据段和低位子数据段;At the storage address of the mantissa data section, respectively read the high-order sub-data section and the low-order sub-data section of the mantissa data section;
    根据所述高位子数据段的数值,在对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;According to the value of the high-order sub-data segment, the first value is found in a preset value table corresponding to the calculation mode, and the preset value table includes the value of the high-order sub-data segment and calculated by a first calculation formula Correspondence of the results obtained;
    将所述高位子数据段的数值和低位子数据段的数值输入加法运算单元,以使所述加法运算单元根据对应所述计算模式的加法运算公式执行运算,得到第二值;Input the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment into an addition unit, so that the addition unit performs an operation according to an addition formula corresponding to the calculation mode to obtain a second value;
    将所述第一值和所述第二值输入第一乘法器,得到第一乘积结果;Input the first value and the second value to a first multiplier to obtain a first product result;
    根据所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值并且存入对应所述浮点数在所述计算模式下的运算结果的尾数数据段地址;According to the first product result, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the address of the mantissa data segment corresponding to the operation result of the floating-point number in the calculation mode ;
    其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。Wherein, the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
  2. 根据权利要求1所述的方法,其特征在于,所述加法运算单元包括选择器和加法器,所述将所述高位子数据段的数值和低位子数据段的数值输入加法运算单元,以使所述加法运算单元执行对应所述计算模式的加法运算公式,得到第二值,包括:The method according to claim 1, wherein the addition operation unit comprises a selector and an adder, and the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment are input to the addition unit, so that The addition operation unit executes the addition operation formula corresponding to the calculation mode to obtain the second value, including:
    将所述低位子数据段的数值输入所述选择器,以使所述选择器为所述低位子数据段的数值赋予与所述计算模式对应的运算系数,获得第三值;Inputting the numerical value of the low-order sub-data segment to the selector, so that the selector assigns the numerical value of the low-order sub-data segment to the calculation coefficient corresponding to the calculation mode to obtain a third value;
    将所述高位子数据段的数值和所述第三值输入所述加法器,得到所述第二值。The numerical value of the high-order sub-data segment and the third value are input to the adder to obtain the second value.
  3. 根据权利要求1或2所述的方法,其特征在于,所述高位子数据段的位数与所述低位子数据位的位数之和等于所述尾数数据段的位数。The method according to claim 1 or 2, wherein the sum of the number of bits in the upper sub-data segment and the number of lower sub-data bits is equal to the number of bits in the mantissa data segment.
  4. 根据权利要求3所述的方法,其特征在于,所述高位子数据段的位数与所述尾数数据段的位数,根据对应所述泰勒展开的余项部分的精度确定。The method according to claim 3, wherein the number of bits in the high-order sub-data segment and the number of bits in the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion.
  5. 根据权利要求1-4任一项所述的方法,其特征在于,所述计算模式包括计算倒数、计算开方、计算开方倒数。The method according to any one of claims 1 to 4, wherein the calculation mode includes calculating the reciprocal, calculating the square root, and calculating the reciprocal square root.
  6. 根据权利要求5所述的方法,其特征在于,The method of claim 5, wherein:
    若所述计算模式包括计算倒数,则所述第一运算公式为
    Figure PCTCN2019108872-appb-100001
    所述加法运算公式为a+(-1)t;
    If the calculation mode includes calculating the reciprocal, the first calculation formula is
    Figure PCTCN2019108872-appb-100001
    The addition operation formula is a+(-1)t;
    若所述计算模式包括计算开方,则所述第一运算公式为
    Figure PCTCN2019108872-appb-100002
    所述加法运算公式为
    Figure PCTCN2019108872-appb-100003
    If the calculation mode includes a square root, the first calculation formula is
    Figure PCTCN2019108872-appb-100002
    The addition operation formula is
    Figure PCTCN2019108872-appb-100003
    若所述计算模式包括计算开方倒数,则所述第一运算公式为
    Figure PCTCN2019108872-appb-100004
    所述加法运算公式为
    Figure PCTCN2019108872-appb-100005
    If the calculation mode includes calculating the reciprocal root, the first calculation formula is
    Figure PCTCN2019108872-appb-100004
    The addition operation formula is
    Figure PCTCN2019108872-appb-100005
    其中,a为所述高位子数据段的数值,t为所述低位子数据段的数值。Wherein, a is the value of the upper sub-data segment, and t is the value of the lower sub-data segment.
  7. 根据权利要求1-6任一项所述的方法,其特征在于,所述根据所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值,包括:The method according to any one of claims 1 to 6, wherein the obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the first product result comprises :
    获取所述第一乘积结果中第一预设数值之后的预设位数的数值;Acquiring the value of the preset number of digits after the first preset value in the first product result;
    根据所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;Obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the value of the preset number of digits;
    其中,所述预设位数为所述尾数数据段的位数。Wherein, the preset number of bits is the number of bits of the mantissa data segment.
  8. 根据权利要求7所述的方法,其特征在于,所述根据所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值,包括:The method according to claim 7, wherein the obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the value of the preset number of digits comprises:
    若所述计算模式包括计算倒数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the reciprocal calculation, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  9. 根据权利要求7所述的方法,其特征在于,所述浮点数还包括:指数数据段;所述根据所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值,包括:The method according to claim 7, wherein the floating-point number further comprises: an exponent data segment; and the calculation result of the floating-point number in the calculation mode is obtained according to the value of the preset number of digits The value of the mantissa data segment, including:
    若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the preset number of bits The value of the mantissa data segment of the result.
  10. 根据权利要求9所述的方法,其特征在于,所述计算模式包括计算 开方,所述根据所述指数数据段的奇偶性以及所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值,包括:The method according to claim 9, wherein the calculation mode includes a square root, and the floating-point number is obtained according to the parity of the exponent data segment and the value of the preset number of bits. The value of the mantissa data segment of the calculation result in the calculation mode includes:
    若所述指数数据段的数值为奇数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an odd number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为偶数,则将所述预设位数的数值以及第二预设数值输入第二乘法器,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an even number, the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after a preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  11. 根据权利要求9所述的方法,其特征在于,所述计算模式包括计算开方倒数,所述根据所述指数数据段的奇偶性以及所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值,包括:The method according to claim 9, wherein the calculation mode includes calculating the reciprocal root of the square, and the floating-point number is obtained according to the parity of the exponent data segment and the value of the preset number of bits. The value of the mantissa data segment of the operation result in the calculation mode includes:
    若所述指数数据段的数值为偶数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an even number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为奇数,则将所述预设位数的数值以及第二预设数值输入第二乘法器,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an odd number, the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after a preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  12. 根据权利要求1-11任一项所述的方法,其特征在于,所述浮点数包括符号数据段;所述方法还包括:The method according to any one of claims 1-11, wherein the floating-point number comprises a symbol data segment; the method further comprises:
    在所述符号数据段的存储地址,读取所述符号数据段的数值;Reading the value of the symbol data segment at the storage address of the symbol data segment;
    根据所述符号数据段的数值,获得所述浮点数在所述计算模式下的运算结果的符号数据段的数值并且存入对应所述浮点数在所述计算模式下的运算结果的符号数据段地址。According to the value of the symbol data segment, the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the symbol data segment corresponding to the operation result of the floating-point number in the calculation mode address.
  13. 根据权利要求12所述的方法,其特征在于,所述根据所述符号数据段的数值,获得所述浮点数在所述计算模式下的运算结果的符号数据段的数值,包括:The method according to claim 12, wherein the obtaining the value of the symbol data segment of the operation result of the floating-point number in the calculation mode according to the value of the symbol data segment comprises:
    若所述计算模式包括计算倒数,则将所述符号数据段的数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值;If the calculation mode includes a reciprocal calculation, use the value of the symbol data segment as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode;
    若所述计算模式包括计算开方或者计算开方倒数,则将第三预设数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the third preset value is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
  14. 根据权利要求1-13任一项所述的方法,其特征在于,所述浮点数包括指数数据段;所述方法还包括:The method according to any one of claims 1-13, wherein the floating-point number comprises an exponent data segment; the method further comprises:
    在所述指数数据段的存储地址,读取所述指数数据段的数值;Reading the value of the index data segment at the storage address of the index data segment;
    根据所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值并且存入对应所述浮点数在所述计算模式下的运算结果的指数数据段地址。According to the value of the exponent data segment, the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the exponent data segment corresponding to the operation result of the floating-point number in the calculation mode address.
  15. 根据权利要求14所述的方法,其特征在于,所述根据所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值,包括:The method according to claim 14, wherein the obtaining the value of the exponent data segment of the operation result of the floating-point number in the calculation mode according to the value of the exponent data segment comprises:
    若所述计算模式包括计算倒数,则根据所述尾数数据段的数值以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值;If the calculation mode includes the reciprocal calculation, obtain the value of the exponent data segment of the operation result of the floating-point number in the calculation mode according to the value of the mantissa data segment and the value of the exponent data segment;
    若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
  16. 根据权利要求15所述的方法,其特征在于,所述根据所述尾数数据段的数值以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值,包括:The method according to claim 15, wherein the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained according to the value of the mantissa data segment and the value of the exponent data segment The value of includes:
    若所述尾数数据段的数值为第三预设值,则将254-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is the third preset value, use the value of 254-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
    若所述尾数数据段的数值不为第三预设值,则将253-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is not the third preset value, use the value of 253-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
    其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
  17. 根据权利要求15所述的方法,其特征在于,所述计算模式包括计算开方,所述根据所述指数数据段的数值的奇偶性以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值,包括:The method according to claim 15, wherein the calculation mode includes a square root, and the floating-point number is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment. The numerical value of the exponent data segment of the calculation result in the calculation mode includes:
    若所述指数数据段的数值为奇数,则将
    Figure PCTCN2019108872-appb-100006
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an odd number, then
    Figure PCTCN2019108872-appb-100006
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为偶数,则将
    Figure PCTCN2019108872-appb-100007
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an even number, then
    Figure PCTCN2019108872-appb-100007
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
  18. 根据权利要求15所述的方法,其特征在于,所述计算模式包括计算开方倒数,所述根据所述指数数据段的数值的奇偶性以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值,包括:The method according to claim 15, wherein the calculation mode includes calculating the reciprocal root of the square, and obtaining the floating-point number according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the exponent data segment of the calculation result in the calculation mode includes:
    若所述指数数据段的数值为奇数且所述尾数数据段的数值不等于第三预设数值,则将
    Figure PCTCN2019108872-appb-100008
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is odd and the value of the mantissa data segment is not equal to the third preset value, then
    Figure PCTCN2019108872-appb-100008
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为奇数且所述尾数数据段的数值等于第三预设数值,则将
    Figure PCTCN2019108872-appb-100009
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then
    Figure PCTCN2019108872-appb-100009
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为偶数,则将
    Figure PCTCN2019108872-appb-100010
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an even number, then
    Figure PCTCN2019108872-appb-100010
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
  19. 一种浮点数处理设备,其特征在于,包括:处理器、加法运算单元、第一乘法器、第一存储装置和第二存储装置;A floating-point number processing device, characterized by comprising: a processor, an addition unit, a first multiplier, a first storage device, and a second storage device;
    所述第一存储装置,用于存储浮点数以及浮点数在计算模式下的运算结果;The first storage device is used to store floating-point numbers and calculation results of floating-point numbers in calculation mode;
    所述第二存储装置,用于存储不同计算模式分别对应的预设数值表;The second storage device is used to store preset value tables corresponding to different calculation modes respectively;
    所述处理器,用于:The processor is used to:
    获取浮点数的处理指令,所述处理指令用于指示浮点数的计算模式,所述浮点数包括尾数数据段;Acquiring a processing instruction of a floating-point number, the processing instruction is used to indicate a calculation mode of the floating-point number, and the floating-point number includes a mantissa data segment;
    在所述尾数数据段的存储地址,从所述第一存储装置中分别读取所述尾数数据段的高位子数据段和低位子数据段;At the storage address of the mantissa data segment, respectively reading the high-order sub-data segment and the low-order sub-data segment of the mantissa data segment from the first storage device;
    根据所述高位子数据段的数值,在所述第二存储装置存储的对应所述计算模式的预设数值表中查找得到第一值,所述预设数值表包括所述高位子数据段的数值与经过第一运算公式计算得到的结果的对应关系;According to the value of the high-order sub-data segment, the first value is obtained by looking up the preset value table corresponding to the calculation mode stored in the second storage device, and the preset value table includes the value of the high-order sub-data segment. Correspondence between the value and the result calculated by the first calculation formula;
    将所述高位子数据段的数值和低位子数据段的数值输入所述加法运算单元,以使所述加法运算单元根据对应所述计算模式的加法运算公式执行运算,得到第二值;Input the numerical value of the high-order sub-data segment and the numerical value of the low-order sub-data segment into the addition unit, so that the addition unit performs an operation according to the addition formula corresponding to the calculation mode to obtain a second value;
    将所述第一值和所述加法运算单元计算得到的所述第二值输入第一乘法 器,得到第一乘积结果;Inputting the first value and the second value calculated by the addition unit into a first multiplier to obtain a first product result;
    根据所述第一乘法器得到的所述第一乘积结果,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值并且存入所述第二存储装置中对应所述浮点数在所述计算模式下的运算结果的尾数数据段地址;According to the first product result obtained by the first multiplier, the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the second storage device corresponding to the float The address of the mantissa data segment of the operation result of the point in the calculation mode;
    其中,第一运算公式与所述加法运算公式的乘积,构成所述计算模式对应的函数表达式的泰勒展开中的多项式部分。Wherein, the product of the first operation formula and the addition operation formula constitutes the polynomial part of the Taylor expansion of the function expression corresponding to the calculation mode.
  20. 根据权利要求19所述的设备,其特征在于,所述加法运算单元包括选择器和加法器,所述处理器,具体用于:The device according to claim 19, wherein the addition operation unit comprises a selector and an adder, and the processor is specifically configured to:
    将所述低位子数据段的数值输入所述选择器,以使所述选择器为所述低位子数据段的数值赋予与所述计算模式对应的运算系数,获得第三值;Inputting the numerical value of the low-order sub-data segment to the selector, so that the selector assigns the numerical value of the low-order sub-data segment to the calculation coefficient corresponding to the calculation mode to obtain a third value;
    将所述高位子数据段的数值和所述第三值输入所述加法器,得到所述第二值。The numerical value of the high-order sub-data segment and the third value are input to the adder to obtain the second value.
  21. 根据权利要求19或20所述的设备,其特征在于,所述高位子数据段的位数与所述低位子数据位的位数之和等于所述尾数数据段的位数。The device according to claim 19 or 20, wherein the sum of the number of bits in the upper sub-data segment and the number of lower sub-data bits is equal to the number of bits in the mantissa data segment.
  22. 根据权利要求21所述的设备,其特征在于,所述高位子数据段的位数与所述尾数数据段的位数,根据对应所述泰勒展开的余项部分的精度确定。The device according to claim 21, wherein the number of bits of the high-order sub-data segment and the number of bits of the mantissa data segment are determined according to the accuracy of the remainder part corresponding to the Taylor expansion.
  23. 根据权利要求19-22任一项所述的设备,其特征在于,所述计算模式包括计算倒数、计算开方、计算开方倒数。The device according to any one of claims 19-22, wherein the calculation mode comprises calculating the reciprocal, calculating the square root, and calculating the reciprocal square root.
  24. 根据权利要求23所述的设备,其特征在于,The device of claim 23, wherein:
    若所述计算模式包括计算倒数,则所述第一运算公式为
    Figure PCTCN2019108872-appb-100011
    所述加法运算公式为a+(-1)t;
    If the calculation mode includes calculating the reciprocal, the first calculation formula is
    Figure PCTCN2019108872-appb-100011
    The addition operation formula is a+(-1)t;
    若所述计算模式包括计算开方,则所述第一运算公式为
    Figure PCTCN2019108872-appb-100012
    所述加法运算公式为
    Figure PCTCN2019108872-appb-100013
    If the calculation mode includes a square root, the first calculation formula is
    Figure PCTCN2019108872-appb-100012
    The addition operation formula is
    Figure PCTCN2019108872-appb-100013
    若所述计算模式包括计算开方倒数,则所述第一运算公式为
    Figure PCTCN2019108872-appb-100014
    所述加法运算公式为
    Figure PCTCN2019108872-appb-100015
    If the calculation mode includes calculating the reciprocal root, the first calculation formula is
    Figure PCTCN2019108872-appb-100014
    The addition operation formula is
    Figure PCTCN2019108872-appb-100015
    其中,a为所述高位子数据段的数值,t为所述低位子数据段的数值。Wherein, a is the value of the upper sub-data segment, and t is the value of the lower sub-data segment.
  25. 根据权利要求19-24任一项所述的设备,其特征在于,所述处理器,具体用于:The device according to any one of claims 19-24, wherein the processor is specifically configured to:
    获取所述第一乘积结果中第一预设数值之后的预设位数的数值;Acquiring the value of the preset number of digits after the first preset value in the first product result;
    根据所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;Obtaining the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode according to the value of the preset number of digits;
    其中,所述预设位数为所述尾数数据段的位数。Wherein, the preset number of bits is the number of bits of the mantissa data segment.
  26. 根据权利要求25所述的设备,其特征在于,所述处理器,具体用于:The device according to claim 25, wherein the processor is specifically configured to:
    若所述计算模式包括计算倒数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the reciprocal calculation, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  27. 根据权利要求25所述的设备,其特征在于,所述浮点数还包括:指数数据段;所述处理器,具体用于:The device according to claim 25, wherein the floating point number further comprises: an exponent data segment; and the processor is specifically configured to:
    若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述预设位数的数值,获得所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the preset number of bits The value of the mantissa data segment of the result.
  28. 根据权利要求27所述的设备,其特征在于,所述计算模式包括计算开方,所述处理器,具体用于:28. The device according to claim 27, wherein the calculation mode includes calculating a square root, and the processor is specifically configured to:
    若所述指数数据段的数值为奇数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an odd number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为偶数,则将所述预设位数的数值以及第二预设数值输入第二乘法器,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an even number, the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after a preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  29. 根据权利要求27所述的设备,其特征在于,所述计算模式包括计算开方倒数,所述处理器,具体用于:The device according to claim 27, wherein the calculation mode comprises calculating the reciprocal root, and the processor is specifically configured to:
    若所述指数数据段的数值为偶数,则将所述预设位数的数值作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值;If the value of the exponent data segment is an even number, the value of the preset number of digits is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为奇数,则将所述预设位数的数值以及第二预设数值输入第二乘法器,获得第二乘法结果,获取所述第二乘积结果中所述第一预设数值之后的预设位数的数值并将其作为所述浮点数在所述计算模式下的运算结果的尾数数据段的数值。If the value of the exponent data segment is an odd number, the value of the preset number of digits and the second preset value are input to the second multiplier to obtain the second multiplication result, and the second multiplication result is obtained. The value of the preset number of digits after a preset value is used as the value of the mantissa data segment of the operation result of the floating-point number in the calculation mode.
  30. 根据权利要求19-29任一项所述的设备,其特征在于,所述浮点数包括符号数据段;所述处理器,还用于:The device according to any one of claims 19-29, wherein the floating-point number comprises a symbol data segment; and the processor is further configured to:
    在所述符号数据段的存储地址,从所述第一存储装置读取所述符号数据 段的数值;At the storage address of the symbol data segment, read the value of the symbol data segment from the first storage device;
    根据所述符号数据段的数值,获得所述浮点数在所述计算模式下的运算结果的符号数据段的数值并且存入所述第一存储装置中对应所述浮点数在所述计算模式下的运算结果的符号数据段地址。According to the value of the symbol data segment, the value of the symbol data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device corresponding to the floating-point number in the calculation mode The address of the symbol data segment of the result of the operation.
  31. 根据权利要求30所述的设备,其特征在于,所述处理器,具体用于:The device according to claim 30, wherein the processor is specifically configured to:
    若所述计算模式包括计算倒数,则将所述符号数据段的数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值;If the calculation mode includes a reciprocal calculation, use the value of the symbol data segment as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode;
    若所述计算模式包括计算开方或者计算开方倒数,则将第三预设数值作为所述浮点数在所述计算模式下的运算结果的符号数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the third preset value is used as the value of the symbol data segment of the operation result of the floating-point number in the calculation mode.
  32. 根据权利要求19-31任一项所述的设备,其特征在于,所述浮点数包括指数数据段;所述处理器,还用于:The device according to any one of claims 19-31, wherein the floating-point number comprises an exponent data segment; and the processor is further configured to:
    在所述指数数据段的存储地址,从所述第一存储装置读取所述指数数据段的数值;Reading the value of the index data segment from the first storage device at the storage address of the index data segment;
    根据所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值并且存入所述第一存储装置中对应所述浮点数在所述计算模式下的运算结果的指数数据段地址。According to the value of the exponent data segment, the value of the exponent data segment of the operation result of the floating-point number in the calculation mode is obtained and stored in the first storage device corresponding to the floating-point number in the calculation mode The address of the exponent data segment of the result of the operation.
  33. 根据权利要求32所述的设备,其特征在于,所述处理器,具体用于:The device according to claim 32, wherein the processor is specifically configured to:
    若所述计算模式包括计算倒数,则根据所述尾数数据段的数值以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值;If the calculation mode includes the reciprocal calculation, obtain the value of the exponent data segment of the operation result of the floating-point number in the calculation mode according to the value of the mantissa data segment and the value of the exponent data segment;
    若所述计算模式包括计算开方或者计算开方倒数,则根据所述指数数据段的数值的奇偶性以及所述指数数据段的数值,获得所述浮点数在所述计算模式下的运算结果的指数数据段的数值。If the calculation mode includes the calculation of the square root or the calculation of the reciprocal root of the square, the calculation result of the floating-point number in the calculation mode is obtained according to the parity of the value of the exponent data segment and the value of the exponent data segment The value of the index data segment.
  34. 根据权利要求33所述的设备,其特征在于,所述计算模式包括计算倒数,所述处理器,具体用于:The device according to claim 33, wherein the calculation mode includes calculating a reciprocal, and the processor is specifically configured to:
    若所述尾数数据段的数值为第三预设值,则将254-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is the third preset value, use the value of 254-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
    若所述尾数数据段的数值不为第三预设值,则将253-E i的数值作为所述浮点数在所述计算模式下的运算结果的指数数据段的数值; If the value of the mantissa data segment is not the third preset value, use the value of 253-E i as the value of the exponent data segment of the operation result of the floating-point number in the calculation mode;
    其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
  35. 根据权利要求33所述的设备,其特征在于,所述计算模式包括计算开方,所述处理器,具体用于:The device according to claim 33, wherein the calculation mode includes calculating a square root, and the processor is specifically configured to:
    若所述指数数据段的数值为奇数,则将
    Figure PCTCN2019108872-appb-100016
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an odd number, then
    Figure PCTCN2019108872-appb-100016
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为偶数,则将
    Figure PCTCN2019108872-appb-100017
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an even number, then
    Figure PCTCN2019108872-appb-100017
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
  36. 根据权利要求33所述的设备,其特征在于,所述计算模式包括计算开方倒数,所述处理器,具体用于:The device according to claim 33, wherein the calculation mode comprises calculating a reciprocal root, and the processor is specifically configured to:
    若所述指数数据段的数值为奇数且所述尾数数据段的数值不等于第三预设数值,则将
    Figure PCTCN2019108872-appb-100018
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is odd and the value of the mantissa data segment is not equal to the third preset value, then
    Figure PCTCN2019108872-appb-100018
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为奇数且所述尾数数据段的数值等于第三预设数值,则将
    Figure PCTCN2019108872-appb-100019
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an odd number and the value of the mantissa data segment is equal to the third preset value, then
    Figure PCTCN2019108872-appb-100019
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    若所述指数数据段的数值为偶数,则将
    Figure PCTCN2019108872-appb-100020
    确定为所述浮点数在所述计算模式下的运算结果的指数数据段的数值;
    If the value of the exponent data segment is an even number, then
    Figure PCTCN2019108872-appb-100020
    The value of the exponent data segment determined as the operation result of the floating-point number in the calculation mode;
    其中,E i为运算前的所述指数数据段的数值。 Wherein, E i is the value of the exponent data segment before calculation.
  37. 一种可移动平台,其特征在于,包括:可移动平台本体以及如权利要求19-36任一项所述的浮点数处理设备,其中,所述浮点数处理设备安装于所述可移动平台本体上。A movable platform, comprising: a movable platform body and the floating-point number processing device according to any one of claims 19-36, wherein the floating-point number processing device is installed on the movable platform body on.
  38. 根据权利要求37所述的可移动平台,其特征在于,所述可移动平台包括手持电话、手持云台、无人机、无人车、无人船、机器人或自动驾驶汽车。The mobile platform according to claim 37, wherein the mobile platform comprises a handheld phone, a handheld pan/tilt, a drone, an unmanned vehicle, an unmanned boat, a robot, or an autonomous vehicle.
  39. 一种可读存储介质,其特征在于,所述可读存储介质上存储有计算机程序;所述计算机程序在被执行时,实现如权利要求1-18任一项所述的浮点数处理方法。A readable storage medium, characterized in that a computer program is stored on the readable storage medium; when the computer program is executed, the floating-point number processing method according to any one of claims 1-18 is realized.
PCT/CN2019/108872 2019-09-29 2019-09-29 Method for processing floating point number, device, and mobile platform WO2021056507A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201980033559.5A CN112189184A (en) 2019-09-29 2019-09-29 Floating point number processing method and device and movable platform
PCT/CN2019/108872 WO2021056507A1 (en) 2019-09-29 2019-09-29 Method for processing floating point number, device, and mobile platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/108872 WO2021056507A1 (en) 2019-09-29 2019-09-29 Method for processing floating point number, device, and mobile platform

Publications (1)

Publication Number Publication Date
WO2021056507A1 true WO2021056507A1 (en) 2021-04-01

Family

ID=73918987

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/108872 WO2021056507A1 (en) 2019-09-29 2019-09-29 Method for processing floating point number, device, and mobile platform

Country Status (2)

Country Link
CN (1) CN112189184A (en)
WO (1) WO2021056507A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112860220B (en) * 2021-02-09 2023-03-24 南方科技大学 Reconfigurable floating-point multiply-add operation unit and method suitable for multi-precision calculation
CN113377334B (en) * 2021-08-16 2021-11-02 北京微核芯科技有限公司 Floating point data processing method and device and storage medium
CN113721884B (en) * 2021-09-01 2022-04-19 北京百度网讯科技有限公司 Operation method, operation device, chip, electronic device and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6205460B1 (en) * 1998-01-30 2001-03-20 Sun Microsystems, Inc. System and method for floating-computation for numbers in delimited floating point representation
CN101216753A (en) * 2008-01-04 2008-07-09 清华大学 Preliminary treatment circuit structure for floating point division and quadratic root algorithm
CN107305484A (en) * 2016-04-19 2017-10-31 北京中科寒武纪科技有限公司 A kind of nonlinear function arithmetic unit and method
CN107423026A (en) * 2017-04-21 2017-12-01 中国人民解放军国防科学技术大学 The implementation method and device that a kind of sin cos functionses calculate

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7188133B2 (en) * 2002-06-20 2007-03-06 Matsushita Electric Industrial Co., Ltd. Floating point number storage method and floating point arithmetic device
CN104598197B (en) * 2015-01-26 2017-05-31 中国科学院自动化研究所 A kind of floating-point inverse and/or inverse square root operation method and its device
JP6410637B2 (en) * 2015-02-25 2018-10-24 ルネサスエレクトロニクス株式会社 Floating point adder, semiconductor device, and control method of floating point adder
CN107291419B (en) * 2017-05-05 2020-07-31 中国科学院计算技术研究所 Floating-point multiplier and floating-point multiplication for neural network processor

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6205460B1 (en) * 1998-01-30 2001-03-20 Sun Microsystems, Inc. System and method for floating-computation for numbers in delimited floating point representation
CN101216753A (en) * 2008-01-04 2008-07-09 清华大学 Preliminary treatment circuit structure for floating point division and quadratic root algorithm
CN107305484A (en) * 2016-04-19 2017-10-31 北京中科寒武纪科技有限公司 A kind of nonlinear function arithmetic unit and method
CN107423026A (en) * 2017-04-21 2017-12-01 中国人民解放军国防科学技术大学 The implementation method and device that a kind of sin cos functionses calculate

Also Published As

Publication number Publication date
CN112189184A (en) 2021-01-05

Similar Documents

Publication Publication Date Title
WO2021056507A1 (en) Method for processing floating point number, device, and mobile platform
US11125561B2 (en) Steering assist
US11024005B2 (en) Optical flow tracking device and method
CN107438752A (en) Localization method, terminal and server
US20220043328A1 (en) Control method for gimbal, controller, and gimbal
WO2019104571A1 (en) Image processing method and device
WO2019084709A1 (en) Method for controlling pan-tilt head, pan-tilt head, control system, and movable device
CN106767767A (en) A kind of micro-nano multimode star sensor system and its data fusion method
US20230366680A1 (en) Initialization method, device, medium and electronic equipment of integrated navigation system
CN107145167B (en) Video target tracking method based on digital image processing technology
CN114612556A (en) Training method of visual inertial odometer model, pose estimation method and pose estimation device
CN109844394B (en) Cloud deck control method and cloud deck
CN109661631A (en) Control method, device and the unmanned plane of unmanned plane
CN112136137A (en) Parameter optimization method and device, control equipment and aircraft
WO2020019175A1 (en) Image processing method and apparatus, and photographing device and unmanned aerial vehicle
US20210105411A1 (en) Determination device, photographing system, movable body, composite system, determination method, and program
WO2021168821A1 (en) Mobile platform control method and device
WO2021217371A1 (en) Control method and apparatus for movable platform
US20210208605A1 (en) Data processing method and device, and unmanned aerial vehicle
CN112129272B (en) Method and device for realizing visual odometer
JP7225876B2 (en) Information processing device, arithmetic processing device, and control method for information processing device
WO2021077427A1 (en) Image processing method and device, and movable platform
CN111238486A (en) Navigation method and device for unmanned equipment, storage medium and unmanned equipment
WO2020107480A1 (en) Image feature point evaluation method and mobile platform
CN115127603B (en) Compensation method and device for magnetic encoder in unmanned aerial vehicle and electronic equipment

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19947041

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19947041

Country of ref document: EP

Kind code of ref document: A1