Data processing method and device and electronic equipment
By emulating the softdouble data type on a processor that does not support double type and converting it to specified type data supported by hardware, the accuracy loss problem caused by the graphics card not supporting double type is solved, and the computing accuracy and efficiency are improved.
Patent Information
- Application Number
- CN202510220771.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-07-18
AI Technical Summary
Some graphics cards do not support double-type data processing, resulting in the loss of accuracy and inaccurate calculation results during large-scale numerical calculations in scientific computing and financial applications.
The software simulates double data, generates softdouble type data, and performs calculations on processors that do not support double type, and then converts the result into specified type data supported by the hardware to improve operation accuracy and accuracy.
It realizes high-precision operations on processors that do not support double type, reduces dependence on software simulation and improves computing efficiency.
Smart Images

Figure CN120335865A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of computers, and particularly relates to a data processing method, apparatus, and electronic device. Background Art
[0002] At present, some graphics cards on the market do not have 64-bit registers, so they cannot perform double (double-precision floating-point number) operations. However, in some special fields (such as scientific computing, financial applications, etc.), there are large-scale numerical calculations, and the data will simultaneously contain very large (such as values greater than the maximum value represented by the float floating-point number range) and very small (such as values less than the minimum value represented by the float floating-point number range) values. In these cases, if float (single-precision floating-point number) is used for operations, there will be a risk of precision loss, and even the correct calculation result cannot be obtained through the operation. Summary of the Invention
[0003] In view of this, the purpose of this application is to provide a data processing method, apparatus, and electronic device to improve the precision and accuracy of data operations.
[0004] The embodiments of this application are implemented as follows:
[0005] In a first aspect, an embodiment of this application provides a data processing method applied to an electronic device. The electronic device includes a first processor and a second processor, and the second processor does not support double-type data processing. The method includes: the first processor simulates double data through software to obtain a target softdouble-type data, and sends the target softdouble-type data to the second processor; the first processor obtains the softdouble-type processing result obtained by the second processor processing the target softdouble-type data; the first processor converts the softdouble-type processing result into data of a specified type supported by the hardware.
[0006] In the above embodiment, a softdouble (soft double-precision floating-point number) data type is obtained by using the method of software simulation of the double type, so that the second processor that does not support double-type data processing can implement the basic function processing of the double type, thereby improving the precision and accuracy of data operations. After the processing of the target softdouble-type data is completed, the softdouble-type processing result is then converted into data of a specified type supported by the hardware to meet the normal data processing requirements, thereby reducing the dependence on software simulation and making better use of the processing power of the hardware, thereby improving the computing efficiency.
[0007] In a possible implementation manner in combination with the embodiments of the first aspect, by software-simulating double data to obtain target softdouble type data, it includes: obtaining a first union containing double type and uint64 type, where all members in the first union share the same memory space; assigning the value of the double data to be simulated to the variable of double type in the first union; assigning the variable of uint64 type in the first union to the variable of uint64 type in the softdouble type to obtain the target softdouble type data.
[0008] In the above embodiment, since all members in the first union share the same memory space, this feature is utilized to implement data type conversion. When the value of the double data to be simulated is assigned to the variable of double type in the first union, the variable of uint64 type in the first union will also change accordingly. Therefore, by accessing the variable of uint64 type in the first union, the underlying binary representation of the double type value can be obtained and assigned to the variable of uint64 type in the softdouble type, so that the target softdouble type data can be obtained, thereby improving the data conversion efficiency.
[0009] In a possible implementation manner in combination with the embodiments of the first aspect, if the specified type is double type, converting the processing result of the softdouble type to the data of the specified type supported by the hardware includes: obtaining a first union containing double type and uint64 type, where all members in the first union share the same memory space; assigning the variable of uint64 type in the processing result of the softdouble type to the variable of uint64 type in the first union; obtaining the variable of double type in the first union to obtain double type data.
[0010] In the above embodiment, since all members in the first union share the same memory space, this feature is utilized to implement data type conversion. When the variable of uint64 type is assigned to the variable of uint64 type in the first union, the variable of double type in the first union will also change accordingly. Therefore, the variable of double type in the first union can be directly obtained, and the double type data can be quickly obtained, which can improve the data conversion efficiency.
[0011] In a possible implementation manner combining with the embodiments of the first aspect, if the specified type is the float type, converting the processing result of the softdouble type into data of the specified type supported by the hardware includes: converting the processing result of the softdouble type into softfloat type data; obtaining a second union including the float type and the uint32 type, where all members in the second union share the same memory space; assigning the value of the softfloat type data to the variable of the uint32 type in the second union; obtaining the variable of the float type in the second union to obtain data of the float type.
[0012] In the above embodiment, when converting the processing result of the softdouble type into the float type, it mainly involves two steps. The first step is to first convert the processing result of the softdouble type into softfloat type data, and the second step is to use the second union to convert the softfloat type data into the float type, so that the data conversion can be completed quickly. Among them, when converting the softfloat type data into the float type, since all members in the second union share the same memory space, this feature is used to implement the conversion of data types. When assigning the value of the softfloat type data to the variable of the uint32 type in the second union, the variable of the float type in the second union will also change accordingly. Therefore, the variable of the float type in the second union can be directly obtained to quickly obtain data of the float type, thereby improving the data conversion efficiency.
[0013] In a possible implementation manner combining with the embodiments of the first aspect, if processing the target softdouble type data includes performing an operation on the target softdouble type data and other data; the method further includes: converting the other data into target data of the softdouble type; where the target data is used to perform an operation on the target softdouble type data.
[0014] In the above embodiment, when the target softdouble type data needs to perform an operation with other data, after converting the other data into the target data of the softdouble type, and then performing the operation with the target softdouble type data, using the operation method of the same data type can improve the operation accuracy.
[0015] Combined with a possible implementation manner of the first aspect embodiment, the other data includes at least one of the following data types: int32, uint32, float, int64, uint64, and double.
[0016] In the above embodiment, the other data includes at least one of the following data types: int32, uint32, float, int64, uint64, and double, so as to cover the calculations of various data types and improve the applicability of the solution.
[0017] Combined with a possible implementation manner of the first aspect embodiment, if the other data is float type data, converting the other data into target data of softdouble type includes: obtaining a second union containing float type and uint32 type, where all members in the second union share the same memory space; assigning the value of the float type data to be converted to the float type variable in the second union; assigning the uint32 type variable in the second union to the uint32 type variable in softfloat type to obtain softfloat data; converting the softfloat data into target data of softdouble type.
[0018] In the above embodiment, when converting float type data into softdouble type, it mainly involves two steps. The first step is to first convert float type into softfloat type data by using the second union, and the second step is to convert the softfloat type data into target data of softdouble type, so that the target data of softdouble type can be obtained quickly. Among them, when converting float type data into softfloat type, since all members in the second union share the same memory space, when assigning the value of the float type data to be converted to the float type variable in the second union, the uint32 type variable in the second union will also change accordingly. Therefore, by assigning the uint32 type variable in the second union to the uint32 type variable in softfloat type, the conversion from float type to softfloat type can be completed quickly.
[0019] In a second aspect, an embodiment of the present application further provides a data processing device, belonging to an electronic device. The electronic device includes a first processor and a second processor, and the second processor does not support data processing of the double type. The device includes: an analog module, an acquisition module, and a conversion module. The analog module is configured to simulate double data through software to obtain target softdouble type data, and send the target softdouble type data to the second processor. The acquisition module is configured to acquire a softdouble type processing result obtained by the second processor processing the target softdouble type data. The conversion module is configured to convert the softdouble type processing result into data of a specified type supported by the hardware.
[0020] In a third aspect, an embodiment of the present application further provides an electronic device, including: a first processor and a second processor. The first processor is configured to simulate double data through software to obtain target softdouble type data. The second processor is connected to the first processor, and the second processor is configured to process the target softdouble type data to obtain a softdouble type processing result. The first processor is further configured to convert the softdouble type processing result into data of a specified type supported by the hardware.
[0021] In a fourth aspect, an embodiment of the present application further provides an electronic device, including: a memory and a processor, and the processor is connected to the memory. The memory is configured to store a program. The processor is configured to call the program stored in the memory to execute the method provided by any possible implementation manner of the first aspect embodiment described above.
[0022] Other features and advantages of the present application will be described in the subsequent specification. The objectives and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written specification and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained according to these drawings. As shown in the drawings, the above-mentioned and other objectives, features, and advantages of the present application will become clearer.
[0024] Figure 1 FIG. 1 shows a schematic structural diagram of an electronic device provided by an embodiment of the present application.
[0025] Figure 2 The schematic diagram of the working principle of an electronic device provided by an embodiment of the present application is shown.
[0026] Figure 3 The schematic flowchart of a data processing method provided by an embodiment of the present application is shown.
[0027] Figure 4 The schematic diagram of the modules of a data processing device provided by an embodiment of the present application is shown.
[0028] Figure 5 The schematic diagram of the structure of another electronic device provided by an embodiment of the present application is shown. Detailed implementation manners
[0029] Next, the technical solutions in the embodiments of the present application will be described with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The following embodiments can be used as examples to more clearly illustrate the technical solutions of the present application, rather than limiting the protection scope of the present application. Those skilled in the art can understand that, without conflict, the features in the following embodiments and the embodiments can be combined with each other.
[0030] It should be noted that: similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of the present application, relational terms such as "first", "second", etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover a non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not expressly listed, or elements inherent to such process, method, article or device.
[0031] Furthermore, the term "and / or" in the present application is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone.
[0032] In the description of the embodiments of the present application, unless otherwise clearly specified and limited, the technical term "connection" may be a direct connection or an indirect connection through an intermediate medium.
[0033] In view of the fact that some graphics cards on the market currently do not support the processing of double - type data, the present application provides a data - processing method. By using software to simulate the double type, a softdouble (software double - precision floating - point number) data type is obtained to implement the basic functions of the double type and the calculations between the double type and other various data types.
[0034] The following will be combined with Figure 1 to describe the electronic device provided by the embodiments of the present application. The data - processing method shown in the present application involves the scenario of data processing and conversion between two processors (the first processor and the second processor). This data - processing method can be applied to the above - mentioned electronic device. As Figure 1 shown, the electronic device includes: a first processor and a second processor, the first processor is connected to the second processor, wherein the second processor does not support the processing of double - type data.
[0035] The first processor is used to obtain target softdouble - type data by software - simulating double data, and send the target softdouble - type data to the second processor. The first processor is used to obtain the softdouble - type processing result obtained by the second processor processing the target softdouble - type data. The first processor is also used to convert (or decode) the softdouble - type processing result into data of a specified type supported by the hardware. By using software to simulate the double type, a softdouble (software double - precision floating - point number) data type is obtained, so that the second processor that does not support the processing of double - type data can implement the basic function processing of the double type, thereby improving the accuracy and precision of data operations.
[0036] In some possible implementation manners, when obtaining target softdouble - type data by software - simulating double data, relevant technologies in the prior art can be used. Details are not described here.
[0037] In some possible implementation manners, the process of obtaining target softdouble - type data by software - simulating double data may include: obtaining a first union containing double type and uint64 (64 - bit unsigned integer) type, and all members in the first union share the same memory space; assigning the value of the double data to be simulated to the double - type variable in the first union; assigning the uint64 - type variable in the first union to the uint64 - type variable in the softdouble type to obtain the target softdouble - type data.
[0038] Data can be saved by using a first union that contains double type and uint64 type, and a softdouble class that contains uint64 type can be created to store data and perform mathematical operations. The first union allows seamless conversion between unsigned integers and floating-point numbers without additional type conversion operations. Since all members in the first union share the same memory space, this feature is utilized to implement data type conversion. That is, when the value of the double data to be simulated is assigned to the double-type variable in the first union, the uint64-type variable in the first union will also change accordingly. Therefore, by accessing the uint64-type variable in the first union, the underlying binary representation of the double type value can be obtained and assigned to the uint64-type variable in the softdouble type, and thus the target softdouble type data can be obtained.
[0039] In some possible implementation manners, the above-mentioned first union may further include int64 type. At this time, the first union includes double type, uint64 type, and int64 (64-bit signed integer) type. The first union can be denoted as Cv64suf.
[0040] In some possible implementation manners, after the second processor processes the target softdouble type data to obtain a softdouble type processing result, the first processor can convert the softdouble type processing result into data of a specified type supported by the hardware. In addition, the second processor can also convert the softdouble type processing result into data of a specified type supported by the hardware and not including double type. That is, if the specified type is double type, only the first processor can perform the conversion. If the specified type is other types that are not double type, the conversion can be performed by the first processor or the second processor.
[0041] Among them, the above-mentioned specified type data includes at least one of the following data: int32 (32-bit integer) type, uint32 (32-bit unsigned integer) type, float (single-precision floating-point number) type, int64 type, uint64 type, and double type.
[0042] In one embodiment, assuming that the specified type is double, when converting the processing result of the softdouble type into data of the specified type supported by the hardware, the process may include: obtaining a first union including double and uint64 types, where all members in the first union share the same memory space; assigning the uint64 type variable in the processing result of the softdouble type to the uint64 type variable in the first union; obtaining the double type variable in the first union to obtain double type data. Since all members in the first union share the same memory space, this feature is utilized to implement the data type conversion. That is, when the uint64 type variable is assigned to the uint64 type variable in the first union, the double type variable in the first union will also change accordingly. Therefore, the double type data can be directly obtained by obtaining the double type variable in the first union.
[0043] In one embodiment, if the specified type is float, when converting the processing result of the softdouble type into data of the specified type supported by the hardware, the process may include: converting the processing result of the softdouble type into softfloat type data; obtaining a second union including float and uint32 types, where all members in the second union share the same memory space; assigning the value of the softfloat type data to the uint32 type variable in the second union; obtaining the float type variable in the second union to obtain float type data. In this embodiment, when converting the processing result of the softdouble type into float type, it mainly involves two steps. The first step is to first convert the processing result of the softdouble type into softfloat type data, and the second step is to use the second union to convert the softfloat type data into float type.
[0044] Since all members in the second union share the same memory space, when the value of the softfloat type data is assigned to the uint32 type variable in the second union, the float type variable in the second union will also change accordingly. Therefore, the float type data can be directly obtained by obtaining the float type variable in the second union.
[0045] In some possible embodiments, data conversion can be performed by using a second union containing float type, uint32 type, and int32 type. At this time, the second union contains float type, uint32 type, and int32 type. The second union can be denoted as Cv32suf.
[0046] When converting the processing result of the softdouble type to the softfloat type, the process can include:
[0047] 1. Obtain the sign (1 bit), exponent (11 bits, offset 1023), and mantissa part (52 bits (including the implicit 1)) of the floating-point number in the processing result of the softdouble type. double is a total of 64 bits;
[0048] 2. Process special cases. If the exponent bit is 0x7FF and the mantissa is non-zero, it means the input is NaN (Not a Number); if the floating-point number exceeds the 32-bit integer range, return a negative overflow value or a positive overflow value; among them, if it is not this special case, this step can be ignored;
[0049] 3. Process zero or very small (the value is less than the minimum value of the float floating-point number representation range) floating-point numbers. Shift the mantissa of the softdouble 22 bits to the right. If both the exponent and the mantissa are 0, it means the value is 0; among them, if the floating-point number is not zero or very small, this step can be ignored;
[0050] 4. For non-zero floating-point numbers, adjust the exponent part and then perform a rounding operation on the mantissa. If the original exponent bit of the softdouble is N, then the exponent bit of the softfloat should be N - 1023 + 127; during the conversion process between softdouble and softfloat, the number of bits of the mantissa part is reduced from 52 bits to 23 bits; since the mantissa needs to be reduced, a rounding operation is required. The goal of the rounding operation is to retain the high-order digits of the original mantissa, discard the low-order part, retain the first 23 bits of the softdouble mantissa, and use the common rounding method of rounding. Determine whether the 24th bit of the softdouble mantissa carries;
[0051] 5. Pack the sign, adjusted exponent, and mantissa part into the softfloat type.
[0052] The following describes how to convert the softdouble type to int32 type, uint32 type, int64 type, and uint64 type. The first occurrence of the process in the following text will be explained, and the process that appears for the second and subsequent times will not be specifically explained.
[0053] The process of converting the softdouble type to the int32 type may include:
[0054] 1. Analyze the sign, exponent, and mantissa of the softdouble floating-point number to obtain the sign bit (0 for positive numbers, 1 for negative numbers), the exponent bit (11 bits), and the mantissa part (52 bits);
[0055] 2. Handle special cases. If the exponent bit is 0x7FF and the mantissa is non-zero, it means the input is NaN (Not a Number). If the floating-point number exceeds the range of 32-bit integers, return a negative overflow value or a positive overflow value. If it is not this special case, this step can be ignored;
[0056] 3. Handle the case of non-zero exponents. If the exponent is non-zero, it indicates a normalized floating-point number, and the mantissa part needs to be supplemented with the implicit most significant bit (0x0010000000000000). If the exponent is zero, this step of processing is not required;
[0057] 4. Calculate the shift amount. This operation calculates the required shift distance based on the exponent of the floating-point number. When converting softdouble back to int32, the exponent part needs to be subtracted by 1023, and the result of the subtraction is the shift distance required;
[0058] 5. Right-shift the mantissa. If the shift distance is greater than 0, the mantissa needs to be right-shifted, and the shifted-out part is recorded as the sticky bit for use during rounding. If the shift distance is less than or equal to 0, this step of processing is not required. For the int32 type, the data representation range is -2 31 to 2 31 -1. If the shift distance is greater than 0, it means the floating-point number has exceeded the maximum range of the int32 type. Therefore, the floating-point number needs to be adjusted to this range by right-shifting the mantissa. For example, there is a softdouble number 2 40 , which cannot be directly represented by int32. To enable int32 to represent this number, the mantissa needs to be right-shifted by 9 bits;
[0059] 6. Round to an integer. Convert the floating-point number to an integer according to the sign, the right-shifted mantissa, the rounding mode (such as rounding), and the precision requirements.
[0060] The process of converting the softdouble type to the uint32 type may include:
[0061] 1. Analyze the sign, exponent, and mantissa of the floating-point number;
[0062] 2. Handle special cases;
[0063] 3. Handle the case of non - zero exponents;
[0064] 4. Calculate the shift amount;
[0065] 5. Right - shift the mantissa;
[0066] 6. Round to an integer.
[0067] The process of converting the softdouble type to the int64 type may include:
[0068] 1. Parse the sign, exponent, and mantissa of the floating - point number;
[0069] 2. Handle special cases;
[0070] 3. Handle the case of non - zero exponents;
[0071] 4. Calculate the shift amount;
[0072] 5. Right - shift the mantissa;
[0073] 6. Round to an integer.
[0074] The process of converting the softdouble type to the uint64 type may include:
[0075] 1. Parse the sign, exponent, and mantissa of the floating - point number;
[0076] 2. Handle special cases;
[0077] 3. Handle the case of non - zero exponents;
[0078] 4. Calculate the shift amount;
[0079] 5. Right - shift the mantissa;
[0080] 6. Round to an integer.
[0081] Among them, when the second processor processes the target softdouble - type data, it can perform conventional operations on the target softdouble - type data, and the operations include at least one of addition, subtraction, multiplication, division, square - root extraction, maximum value, minimum value, greater than, less than, equal to, absolute value, sine, cosine, tangent, arcsine, arccosine, arctangent, azimuth, power exponent, exponent, logarithm, etc. In some possible implementation manners, if processing the target softdouble - type data includes performing an operation on the target softdouble - type data and other data, the first processor can also be used to convert the other data into the target data of the softdouble type; wherein, the target data is used to perform an operation with the target softdouble - type data.
[0082] Among them, other data includes at least one of the following data types: int32, uint32, float, int64, uint64, and double. In some possible implementation manners, if the type of other data does not include the double type, the second processor can also convert the other data into target data of the softdouble type, that is, if the other data is of the double type, only the first processor can perform the conversion, and if the other data is not of the double type, the conversion can be performed by the first processor or the second processor.
[0083] In one embodiment, when converting other data of the float type into target data of the softdouble type, the process may include: obtaining a second union including the float type and the uint32 type, where all members in the second union share the same memory space; assigning the value of the float type data to be converted to the float type variable in the second union; assigning the uint32 type variable in the second union to the uint32 type variable in the softfloat type to obtain softfloat data; and converting the softfloat data into target data of the softdouble type. In this embodiment, when converting float type data into softdouble type, mainly two steps are involved. The first step is to first convert the float type into softfloat type data by using the second union, and the second step is to convert the softfloat type data into target data of the softdouble type.
[0084] Since all members in the second union share the same memory space, when assigning the value of the float type data to be converted to the float type variable in the second union, the uint32 type variable in the second union will also change accordingly. Therefore, by assigning the uint32 type variable in the second union to the uint32 type variable in the softfloat type, the conversion from the float type to the softfloat type can be completed.
[0085] When converting softfloat type data into target data of the softdouble type, the process may include:
[0086] 1. Obtain the sign (1 bit), exponent (8 bits, with an offset of 127), and mantissa part (23 bits (including the implicit 1)) of the input float floating-point number, where the float has a total of 32 bits;
[0087] 2. Handle the cases where the input is NaN or infinity. If the exponent bit is 0x7FF and the mantissa is non-zero, it indicates that the input is NaN. If the mantissa bit is 0, the number is infinity, and it also needs to be represented as the infinity of softdouble. Among them, this step is a special detection, and if this special situation is not met, it can be ignored;
[0088] 3. Normalization processing: perform normalization processing on the mantissa part to obtain the normalized exponent and mantissa parts;
[0089] 4. Process the normalized floating-point number: process the normalized result, add the offset 0x380 to the exponent, and shift the fractional part 29 bits to the left;
[0090] 5. Pack the sign, the normalized exponent, and the fractional part to obtain softdouble.
[0091] The following describes how to convert data of int32 type, uint32 type, int64 type, and uint64 type to softdouble type. The processes that appear for the first time in the following text will be explained, and the processes that appear for the second and subsequent times will not be specifically explained.
[0092] In one embodiment, the process of converting int64 type data to the target data of softdouble type may include:
[0093] 1. Sign bit judgment: First, determine whether the input integer is negative; here, a sign bit sign is used to record the positive and negative of the int64 type variable. For a negative number, the sign bit of the floating-point number is set to 1, and for a positive number, the sign bit remains 0;
[0094] 2. Zero value check: If the integer value is zero, it is directly processed into "positive zero" or "negative zero" that conforms to the IEEE 754 standard, and no further conversion is required at this time;
[0095] 3. Absolute value calculation: If the int64 type variable is non-zero, take the absolute value of the negative number to obtain the unsigned integer form; if the int64 type variable is positive, this operation is not required;
[0096] 4. Mantissa normalization: Adjust the number of bits of the unsigned integer to the standard form of the floating-point mantissa. This process can be achieved by finding the most significant bit and adjusting the mantissa bits according to the IEEE 754 format to make the mantissa conform to the specification; for example, find the most significant bit through a left shift operation and normalize the unsigned integer to the form where the highest bit of the mantissa is 1;
[0097] 5. Exponent adjustment: Adjust the 11-bit exponent part of the floating-point number according to the 52 effective bits of the mantissa;
[0098] 6. Rounding operation. According to the IEEE 754 double-precision floating-point format, the mantissa can only have 52 bits. Rounding operations (such as rounding up or down) need to be performed to adjust the mantissa to ensure that the conversion result meets the accuracy requirements.
[0099] 7. Packing. Pack the sign, exponent, and mantissa into a variable of type uint64 and pass it to the variable of type uint64 in the softdouble type.
[0100] Among them, softdouble has a total of 64 bits, including 1 sign bit, 11 exponent bits, and 52 mantissa bits. The following takes the conversion of int64 100 to softdouble as an example, and a complete conversion process is as follows:
[0101] 1. Check the sign bit. 100 is a positive number, and the sign bit is 0.
[0102] 2. Zero value check. 100 is not 0.
[0103] 3. Absolute value calculation. No operation is required for positive numbers.
[0104] 4. Mantissa normalization. The binary representation of 100 is 1100100. Normalization means moving the decimal point of the binary number behind the first 1. So 1100100 will become 1.100100×2^6.
[0105] 5. Exponent adjustment. Since the decimal point has been offset by 6 bits, the actual exponent is 6 + 1023 = 1029. Convert 1029 to binary: 10000000101.
[0106] 6. Rounding operation. The rounding operation is also performed under certain circumstances. If the mantissa part of a number is represented as a binary number greater than 52 bits, then the rounding operation needs to be performed to ensure that the mantissa part does not exceed 52 bits. In the IEEE 754 double-precision floating-point standard, rounding up or down is usually used to handle the extra bits. In this example, no rounding operation is required.
[0107] 7. Packing. Among them, the sign bit is 0; the exponent bits: 10000000101 (representing the exponent 6, plus the offset 1023); the mantissa: in the IEEE 754 double-precision format, the representation of the mantissa is normalized, and the 1 to the left of the decimal point does not need to be explicitly stored because it is implicit. So only the remaining part of the mantissa is stored. The previous mantissa was 1100100. Without storing the first 1, the mantissa is 100100. The mantissa has a total of 52 bits and is padded to: 1001000000000000000000000000000000000000000000000000; then combine the sign bit, exponent part, and mantissa part.
[0108] In one embodiment, the process of converting uint64 - type data into target data of softdouble type may include:
[0109] 1. Zero - value check. If it is zero, directly return a softdouble variable representing zero;
[0110] 2. Mantissa normalization;
[0111] 3. Handling the case where the high - order bit is 1. If the highest - order bit of the input value is 1 (i.e., the value is greater than or equal to 2^63), after mantissa normalization, a right - shift operation needs to be performed on the mantissa, and at the same time, ensure that there is a carry - handling at the end (i.e., the lowest - order bit of the mantissa may become non - zero due to right - shift). If the value of a uint64 - type variable N is greater than or equal to 2 to the 63rd power, it means this number is very large. The number of bits for storing the mantissa is 52 bits, and there will be a situation where it cannot be stored in 52 bits. However, the given number of mantissa bits is 52 bits, so the mantissa needs to be right - shifted. The specific amount of right - shift depends on the position of the most significant bit in the binary representation of the unsigned integer;
[0112] 4. Exponent adjustment;
[0113] 5. Overflow and underflow handling. If the processed mantissa and exponent exceed the representation range of IEEE 754 double - precision (i.e., the exponent is too large), then trigger overflow handling, and the result returns infinity; if the mantissa becomes too small (close to zero), then according to the rounding rule, it may trigger an underflow flag, resulting in the result being zero; this step is a special handling. If the processed mantissa and exponent are within the normal range, this step can be ignored;
[0114] 6. Rounding operation;
[0115] 7. Packing.
[0116] In one embodiment, the process of converting int32 - type data into target data of softdouble type may include:
[0117] 1. Sign - bit judgment;
[0118] 2. Zero - value check;
[0119] 3. Absolute - value calculation;
[0120] 4. Mantissa normalization;
[0121] 5. Exponent adjustment;
[0122] 6. Rounding operation;
[0123] 7. Packing.
[0124] In one embodiment, the process of converting uint32 type data into target data of softdouble type may include:
[0125] 1. Zero value check;
[0126] 2. Mantissa normalization;
[0127] 3. Exponent adjustment;
[0128] 4. Overflow and underflow handling;
[0129] 5. Rounding operation;
[0130] 6. Packing.
[0131] In some possible implementation manners, the above first processor may be a Central Processing Unit (CPU), a Network Processor (NP), a Multimedia Application Processor (MAP), a microprocessor, etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The second processor may be a Graphics Processing Unit (GPU), an Accelerated Processing Unit, etc.
[0132] In some possible implementation manners, the working principle of the above electronic device may be as Figure 2 shown. Figure 2 Only the case where the first processor is a CPU and the second processor is a GPU is shown. On the CPU side, common data types including double type can be encoded into softdouble data type and sent to the GPU side. On the GPU side, common data types other than double type can be encoded into softdouble data type. Then, the processing of softdouble data type is completed on the GPU side. Then, on the CPU side, the softdouble data type can be decoded into common data types including double type, or on the GPU side, the softdouble data type can be decoded into common data types other than double type.
[0133] Based on the same inventive concept, an embodiment of this application further provides a data processing method, which is applied to the above-mentioned electronic device. The following will be combined with Figure 3 to illustrate the data processing method provided by the embodiment of this application.
[0134] S1: The first processor simulates double data through software to obtain target softdouble type data, and sends the target softdouble type data to the second processor.
[0135] In a possible implementation manner, the specific process of S1 may include: obtaining a first union including double type and uint64 type, where all members in the first union share the same memory space; assigning the value of the double data to be simulated to the double type variable in the first union; assigning the uint64 type variable in the first union to the uint64 type variable in the softdouble type to obtain the target softdouble type data.
[0136] S2: The first processor obtains the softdouble type processing result obtained by the second processor processing the target softdouble type data.
[0137] In some possible implementation manners, if the processing of the target softdouble type data includes performing an operation on the target softdouble type data and other data, the above data conversion method may further include: converting the other data into target data of the softdouble type; where the target data is used to perform an operation on the target softdouble type data.
[0138] Among them, the other data includes at least one of int32 type, uint32 type, float type, int64 type, uint64 type, and double type data.
[0139] In one embodiment, when other data is float-type data, the process of converting the other data into target data of the softdouble type includes: obtaining a second union including a float type and a uint32 type, where all members in the second union share the same memory space; assigning the value of the float-type data to be converted to the float-type variable in the second union; assigning the uint32-type variable in the second union to the uint32-type variable in the softfloat type to obtain softfloat data; and converting the softfloat data into target data of the softdouble type.
[0140] S3: The first processor converts the processing result of the softdouble type into data of a specified type supported by the hardware.
[0141] In one embodiment, when the specified type is the double type, the specific process of S3 may include: obtaining a first union including a double type and a uint64 type, where all members in the first union share the same memory space; assigning the uint64-type variable in the processing result of the softdouble type to the uint64-type variable in the first union; and obtaining the double-type variable in the first union to obtain double-type data.
[0142] In one embodiment, when the specified type is the float type, the specific process of S3 may include: converting the processing result of the softdouble type into softfloat-type data; obtaining a second union including a float type and a uint32 type, where all members in the second union share the same memory space; assigning the value of the softfloat-type data to the uint32-type variable in the second union; and obtaining the float-type variable in the second union to obtain float-type data.
[0143] The data processing method provided in the embodiments of the present application has the same implementation principle and the same technical effects as those in the foregoing embodiments of the electronic device. For a brief description, for the parts not mentioned in the method embodiments, reference may be made to the corresponding content in the foregoing embodiments of the electronic device.
[0144] Based on the same inventive concept, the embodiments of the present application further provide a data processing device belonging to an electronic device. The electronic device includes a first processor and a second processor, and the second processor does not support data processing of the double type. As Figure 4 shown, the device includes: an analog module, an acquisition module, and a conversion module.
[0145] Among them, the simulation module is used to simulate double data through software to obtain target softdouble type data, and send the target softdouble type data to the second processor.
[0146] The acquisition module is used to acquire the processing result of the softdouble type obtained by the second processor processing the target softdouble type data.
[0147] The conversion module is used to convert the processing result of the softdouble type into data of a specified type supported by the hardware.
[0148] In one embodiment, the simulation module is used to: acquire a first union including double type and uint64 type, and all members in the first union share the same memory space; assign the value of the double data to be simulated to the double type variable in the first union; assign the uint64 type variable in the first union to the uint64 type variable in the softdouble type to obtain the target softdouble type data.
[0149] In one embodiment, if the specified type is double type, the conversion module is used to: acquire a first union including double type and uint64 type, and all members in the first union share the same memory space; assign the uint64 type variable in the processing result of the softdouble type to the uint64 type variable in the first union; acquire the double type variable in the first union to obtain double type data.
[0150] In one embodiment, if the specified type is float type, the conversion module is used to: convert the processing result of the softdouble type into softfloat type data; acquire a second union including float type and uint32 type, and all members in the second union share the same memory space; assign the value of the softfloat type data to the uint32 type variable in the second union; acquire the float type variable in the second union to obtain float type data.
[0151] If processing the target softdouble type data includes performing operations on the target softdouble type data and other data, the above-mentioned conversion module is also used to convert the other data into target data of softdouble type; wherein the target data is used to perform operations on the target softdouble type data.
[0152] In one embodiment, if the other data is float type data, the conversion module is also used to obtain a second union including float type and uint32 type, and all members in the second union share the same memory space; assign the numerical value of the float type data to be converted to the float type variable in the second union; assign the uint32 type variable in the second union to the uint32 type variable in the softfloat type to obtain softfloat data; and convert the softfloat data into softdouble type target data.
[0153] The data processing device provided in the embodiment of the present application has the same implementation principle and technical effects as those in the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.
[0154] In some possible implementations, the above-mentioned electronic device may further include other components, such as Figure 5 As shown, the electronic device includes: a transceiver, a memory, a communication bus and a processor. The processor may include the first processor and the second processor mentioned above.
[0155] The transceiver, the memory, and the processor are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines. The transceiver is used to send and receive data. The memory is used to store computer programs, such as Figure 4 The software function module shown in is a data processing device. The data processing device includes at least one software function module that can be stored in the memory in the form of software or firmware or solidified in the operating system (OS) of the electronic device. The first processor is used to execute an executable module stored in the memory, such as a software function module or a computer program included in the data processing device. For example, the first processor is used to execute the above-mentioned data processing method.
[0156] Among them, the memory can be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electric Erasable Programmable Read-Only Memory (EEPROM), etc.
[0157] Among them, the above-mentioned electronic devices include, but are not limited to, smart phones, tablets, computers, servers, etc.
[0158] The embodiment of the present application also provides a non-volatile computer-readable storage medium (hereinafter referred to as the storage medium). A computer program is stored on the storage medium. When the computer program is run by a computer such as the above-mentioned electronic device, the data processing method shown above is executed.
[0159] It should be noted that the embodiments in this specification are all described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts among the embodiments can be referred to each other.
[0160] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are only illustrative. For example, the flowcharts and block diagrams in the drawings show the possible architectures, functions, and operations of devices, methods, and computer program products according to multiple embodiments of the present application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order from that marked in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0161] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist alone, or two or more modules may be integrated to form an independent part.
[0162] If the above-mentioned function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the essence of the technical solution of the present application, or the part that contributes to the prior art, or a part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a computer-readable storage medium and includes several instructions for causing a computer device (which may be a personal computer, a laptop, a server, or an electronic device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned computer-readable storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.
[0163] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present application can easily think of changes or substitutions, which should all be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A data processing method, characterized in that, Applied to an electronic device, the electronic device includes a first processor and a second processor, and the second processor does not support data processing of the double type; the method includes: The first processor simulates double data through software to obtain target softdouble type data, and sends the target softdouble type data to the second processor; The first processor obtains the softdouble type processing result obtained by the second processor processing the target softdouble type data; The first processor converts the softdouble type processing result into data of a specified type supported by the hardware.
2. The data processing method according to claim 1, wherein Simulating double data through software to obtain target softdouble type data includes: Obtaining a first union including double type and uint64 type, and all members in the first union share the same memory space; Assigning the value of the double data to be simulated to the double type variable in the first union; Assigning the uint64 type variable in the first union to the uint64 type variable in the softdouble type to obtain target softdouble type data.
3. The data processing method according to claim 1, characterized in that If the specified type is double type, converting the softdouble type processing result into data of a specified type supported by the hardware includes: Obtaining a first union including double type and uint64 type, and all members in the first union share the same memory space; Assigning the uint64 type variable in the softdouble type processing result to the uint64 type variable in the first union; Obtaining the double type variable in the first union to obtain double type data.
4. The data processing method according to claim 1, wherein If the specified type is float type, converting the softdouble type processing result into data of a specified type supported by the hardware includes: Converting the softdouble type processing result into softfloat type data; Obtaining a second union including float type and uint32 type, and all members in the second union share the same memory space; Assigning the value of the softfloat type data to the uint32 type variable in the second union; Obtaining the float type variable in the second union to obtain float type data.
5. The data processing method according to any one of claims 1-4, characterized in that If processing the target softdouble type data includes performing an operation on the target softdouble type data and other data; the method further includes: Converting the other data into target data of softdouble type; wherein, the target data is used to perform an operation on the target softdouble type data.
6. The data processing method according to claim 5, wherein The other data includes at least one of the following types of data: int32, uint32, float, int64, uint64, double.
7. The data processing method according to claim 5, wherein If the other data is float type data, converting the other data into target data of softdouble type includes: Obtaining a second union including float type and uint32 type, where all members in the second union share the same memory space; Assigning the value of the float type data to be converted to the float type variable in the second union; Assigning the uint32 type variable in the second union to the uint32 type variable in softfloat type to obtain softfloat data; Converting the softfloat data into target data of softdouble type.
8. A data processing device, characterized in that, Belonging to an electronic device, the electronic device includes a first processor and a second processor, and the second processor does not support double type data processing; the device includes: An analog module, configured to simulate double data through software to obtain target softdouble type data, and send the target softdouble type data to the second processor; An acquisition module, configured to acquire the softdouble type processing result obtained by the second processor processing the target softdouble type data; A conversion module, configured to convert the softdouble type processing result into data of a specified type supported by hardware.
9. An electronic device, characterized in that, Includes: A first processor, configured to simulate double data through software to obtain target softdouble type data; A second processor, connected to the first processor, where the second processor is configured to process the target softdouble type data to obtain a softdouble type processing result; The first processor is further configured to convert the softdouble type processing result into data of a specified type supported by hardware.
10. An electronic device, characterized in that, Includes: A memory and a processor, where the processor is connected to the memory; The memory is configured to store a program; The processor is configured to call the program stored in the memory to execute the method according to any one of claims 1-7.