Data format conversion device and method, electronic equipment, and computer storage medium
By introducing an intermediate floating point format into the data format conversion hardware circuit and using its maximum bit width to support the conversion of multiple data formats, the problems of limited functions and high resource consumption in the existing technology are solved, and the diversity and efficiency improvement is achieved .
Patent Information
- Application Number
- CN202410267651.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-08
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2044-03-08
AI Technical Summary
The existing data format conversion hardware circuit has limited functions and consumes a lot of hardware resources, so it is impossible to effectively realize the conversion between multiple data formats.
Data conversion is carried out using the intermediate floating point format. The data to be converted into the intermediate floating point format through the first conversion module, and the second conversion module converts it into the target format data, the exponential bit width and mantissa bits of the intermediate floating point format The width is the maximum configuration bit width of preset multiple formats to support the conversion of multiple data formats.
It reduces the consumption of hardware resources, improves the diversity and efficiency of data format conversion, and realizes flexible conversion between multiple data formats.
Smart Images

Figure CN118051200B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of circuit technology, and in particular to a data format conversion device and method, an electronic device, and a computer storage medium. Background Art
[0002] At present, among integers and floating-point numbers in multiple formats, a specific hardware circuit can usually be used to convert a specific format into another specific format, or a larger bit width can be configured on the hardware circuit to achieve format conversion between specific formats; in this way, the data format that can be converted by the data format conversion circuit implemented by the hardware circuit is limited, and the consumption of hardware resources is large, resulting in poor functionality of the data format conversion hardware circuit. Summary of the invention
[0003] The embodiments of the present application provide a data format conversion device and method, an electronic device, and a computer storage medium, which can reduce the consumption of hardware resources and increase the diversity of formats supported by data conversion, thereby improving the function of the data format conversion hardware circuit.
[0004] The technical solution of this application is implemented as follows:
[0005] The present application provides a data format conversion device, including:
[0006] A first conversion module, used for converting data to be converted in any one of a plurality of preset data formats into intermediate data in an intermediate floating point format; the intermediate exponent bit width of the intermediate floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to the plurality of preset formats; the intermediate mantissa bit width of the intermediate floating point format is the maximum value of the bit widths of a plurality of configuration mantissas corresponding to the plurality of preset data formats; the bit width of the configuration exponent of each data format is used to characterize the numerical range of the data format; the bit width of the configuration mantissa of each data format is used to characterize the data precision of the data format;
[0007] The second conversion module is used to convert the intermediate data into the target format data according to a conversion method matching the target format data; the target format of the target format data is any one of the preset multiple data formats.
[0008] The present application provides a data format conversion method, including:
[0009] Through the first conversion module, the data to be converted in any one of the preset multiple data formats is converted into intermediate data in an intermediate floating point format; the intermediate exponent bit width of the intermediate floating point format is the maximum value of the bit widths of multiple configuration exponents corresponding to the preset multiple formats; the intermediate mantissa bit width of the intermediate floating point format is the maximum value of the bit widths of multiple configuration mantissas corresponding to the preset multiple data formats; the bit width of the configuration exponent of each data format is used to characterize the numerical range of the data format; the bit width of the configuration mantissa of each data format is used to characterize the data precision of the data format;
[0010] The intermediate data is converted into the target format data by a second conversion module in a conversion manner matching the target format data; the target format data has a target format that is any one of the preset multiple data formats.
[0011] An embodiment of the present application provides an electronic device, including:
[0012] Memory for storing computer programs;
[0013] The processor is used to execute the above data format conversion method when the computer program is running.
[0014] An embodiment of the present application provides a computer-readable storage medium having executable instructions stored thereon, which are used to implement the above-mentioned data format conversion method when executed by a processor.
[0015] The embodiment of the present application provides a data format conversion device and method, an electronic device, and a computer storage medium. Since the data format conversion device first converts the data to be converted into intermediate data of an intermediate floating point format, and then converts the intermediate data into target format data, and the intermediate mantissa bit width of the intermediate floating point format is the maximum value of the bit width of multiple configuration exponents corresponding to the preset multiple formats, and the intermediate mantissa bit width is the maximum value of the bit width of multiple configuration mantissas corresponding to the preset multiple formats; that is, the value range of the intermediate floating point format is the minimum value that can meet the data range of the preset multiple formats, and the data precision of the intermediate floating point format is the minimum value that can meet the data precision of the preset multiple formats. Therefore, setting the intermediate floating point format can enable the data format conversion device to realize mutual conversion between the preset multiple data formats, and improve the diversity of data conversion. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 1 ;
[0017] Figure 2 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 2 ;
[0018] Figure 3 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 3 ;
[0019] Figure 4 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 4 ;
[0020] Figure 5 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 5 ;
[0021] Figure 6 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 6 ;
[0022] Figure 7 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 7 ;
[0023] Figure 8 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 8 ;
[0024] Fig. 9 A schematic diagram of a first shift process provided in an embodiment of the present application Figure 1 ;
[0025] Fig.10 A schematic diagram of a first shift process provided in an embodiment of the present application Figure 2 ;
[0026] Fig.11 A schematic diagram of a first shift process provided in an embodiment of the present application Figure 3 ;
[0027] Fig.12 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 9 ;
[0028] Fig.13 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 10 ;
[0029] Fig.14 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 10 one;
[0030] Fig.15 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 10two;
[0031] Fig.16 A schematic diagram of a color value determination device provided in an embodiment of the present application Figure 10 three;
[0032] Fig.17 A schematic diagram of a data format conversion device provided in an embodiment of the present application Figure 10 Four;
[0033] Fig.18 A flowchart of a data format conversion method provided in an embodiment of the present application;
[0034] Fig.19 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0036] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0037] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0038] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0039] To facilitate understanding of the present solution, before describing the embodiments of the present application, the application background of the embodiments of the present application is described.
[0040] With the development of computer technology, computers usually need a graphics processing unit (GPU) to perform data calculations to reduce the graphics card's dependence on the central processing unit (CPU). Due to the different data formats stored between the GPU and the CPU, or between the GPU and the graphics card and other hardware circuits, the GPU often needs to convert data of different formats, including floating point numbers of various formats and integers of various formats. For example, the data format stored in the graphics card is a 32-bit floating point number, and the data format stored in the GPU is an additional 16-bit floating point number, etc. Among them, converting data of a certain format into data of another certain format usually requires a specific circuit to implement. Exemplarily, on the basis of a theoretical method for converting any floating point number into any integer, once it is implemented in a specific hardware circuit, the hardware circuit can usually only realize the conversion of a floating point number of a certain format into an integer of a certain format. In other words, the data conversion format that can be realized by a hardware circuit is very single. If a hardware circuit wants to realize the conversion between multiple formats, it is necessary to set a larger bit width, resulting in redundant bit width and wasting hardware resources.
[0041] In order to solve the above problems, the embodiment of the present application provides a data format conversion device, which can convert data in preset multiple formats through a hardware circuit when multiple formats are preset. The device can be applied to any device that needs to be converted in preset multiple formats. In some embodiments, the device can be set on a device that needs to calculate data through a graphics processor (Graph Processing Unit, GPU), so that the diversity of data formats supported by the device can be improved. These devices can be servers, laptops, tablet computers, desktop computers, smart TVs, set-top boxes, mobile devices (such as mobile phones, portable video players, personal digital assistants, dedicated messaging devices, portable gaming devices), etc.
[0042] Figure 1 The following is a schematic diagram of the structure of an optional data format conversion device provided in an embodiment of the present application. Figure 1As shown, the device may include: a first conversion module 10, used to convert the data to be converted in any one of a plurality of preset data formats into intermediate data in an intermediate floating-point format; the intermediate exponent bit width of the intermediate floating-point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to the plurality of preset formats; the intermediate mantissa bit width of the intermediate floating-point format is the maximum value of the bit widths of a plurality of configuration mantissas corresponding to the plurality of preset data formats; the bit width of the configuration exponent of each data format is used to characterize the numerical range of the data format; the bit width of the configuration mantissa of each data format is used to characterize the data precision of the data format; a second conversion module 20, used to convert the intermediate data into target format data in accordance with a conversion method matching the target format data; the target format of the target format data is any one of a plurality of preset data formats.
[0043] In an embodiment of the present application, the data format conversion device can realize format conversion in a plurality of preset data formats. The preset plurality of data formats may include a plurality of floating point formats and a plurality of integer formats; here, the preset plurality of data formats can be set as needed, and the embodiment of the present application does not limit it.
[0044] In the embodiment of the present application, the data format conversion device can first convert the input data to be converted into an intermediate floating point format through the first conversion module 10, and then convert the intermediate floating point format into a target format among the preset multiple data formats through the second conversion module 20.
[0045] In the embodiment of the present application, the intermediate floating point format includes a sign bit, an exponent bit, and a mantissa bit; wherein the bit width of the exponent bit is the intermediate exponent bit width, the bit width of the mantissa bit is the intermediate mantissa bit width, and the bit width of the sign bit is 1. When the intermediate exponent bit width and the intermediate exponent bit width are determined, the intermediate floating point format is determined.
[0046] In the embodiment of the present application, the bit width of the configuration index of each format is used to characterize the numerical range of the format, that is, the data range that can be represented by the bit width of the configuration index of each format should be greater than or equal to the data range of the format itself. The bit width of the configuration mantissa of each format is used to represent the numerical precision of the format, that is, the bit width of the configuration mantissa of each format should be the bit width of the mantissa represented by the format; here, the bit width of the mantissa represented by the integer format is the bit width of the integer format itself.
[0047] It should be noted that, for any integer format, the bit width int_pw of its configuration exponent can completely cover the range of values that it can represent when satisfying formula (1) and formula (2).
[0048] 2 int_pw -1-bias≥int_w-1 formula (1)
[0049] bias=2(int_pw-1) -1 Formula (2)
[0050] For example, if the bit width of the integer is 32, according to formula (1) and formula (2), the minimum bit width of the configuration index int_pw can be 6. If the bit width of the integer is 16, it can be determined that the minimum bit width of the configuration index can be 5.
[0051] In an embodiment of the present application, the bit width of the configuration exponent and the bit width of the configuration mantissa of each of the preset multiple data formats can be determined according to the format, and the intermediate exponent bit width can be the maximum value of the bit widths of the multiple configuration exponents corresponding to the preset multiple data formats; in this way, the data range that can be represented by the intermediate exponent bit width can be greater than or equal to the maximum data range of the preset multiple data formats; the intermediate mantissa bit width can be the maximum value of the bit widths of the multiple configuration mantissas corresponding to the preset multiple data formats. Here, the intermediate exponent bit width and the intermediate mantissa bit width of the intermediate floating-point format can be determined according to the preset multiple data formats, and the embodiment of the present application does not limit this.
[0052] It should be noted that the data precision that can be represented by the intermediate mantissa bit width can be greater than or equal to the maximum data precision of the preset multiple data formats; that is, the intermediate floating-point format can accurately represent the data of each format in the preset multiple data formats. In some embodiments, the data precision that can be represented by the intermediate mantissa bit width is equal to the maximum data precision of the preset multiple data formats; at this time, the intermediate floating-point format has the least number of bits, which ensures data precision while saving hardware resources to the greatest extent. In an embodiment of the present application, after the data format conversion device converts the data to be converted into the intermediate floating-point format through the first conversion module 10, the intermediate data in the intermediate floating-point format can be converted into the target format data through the second conversion module 20 according to the target format of the target format data and in accordance with the conversion method of converting the intermediate floating-point format into the target format.
[0053] In some embodiments of the present application, the target format is a floating point format, and the second conversion module 20 can convert the intermediate floating point format into any one of a plurality of preset data formats.
[0054] In some embodiments of the present application, the target format is an integer format, and the second conversion module 20 can convert the intermediate floating point format into any integer format of a plurality of preset data formats. Here, in the process of converting the intermediate floating point format into the integer format, the integer can be rounded directly or the integer can be rounded according to the decimal. The rounding method can be rounding to the nearest even (RNE), etc., which can be set as needed, and the embodiment of the present application does not limit it.
[0055] It can be understood that, since the data format conversion device first converts the data to be converted into intermediate data of the intermediate floating point format, and then converts the intermediate data into the target format data, and the intermediate mantissa bit width of the intermediate floating point format is the maximum value of the bit width of multiple configuration exponents corresponding to the preset multiple formats, and the intermediate mantissa bit width is the maximum value of the bit width of multiple configuration mantissas corresponding to the preset multiple formats; that is, the value range of the intermediate floating point format is the minimum value that can meet the data range of the preset multiple formats, and the data precision of the intermediate floating point format is the minimum value that can meet the data precision of the preset multiple formats. Therefore, setting the intermediate floating point format can enable the data format conversion device to realize mutual conversion between the preset multiple data formats, and improve the diversity of data conversion.
[0056] based on Figure 1 , Figure 2 FIG. 2 shows a schematic diagram of the structure of an optional data conversion device. Figure 2 As shown, the data format conversion device 10 may further include an acquisition module 30 and a determination module 40; wherein the acquisition module 30 is used to acquire the bit width of the configuration exponent and the bit width of the configuration mantissa of each data format in the preset multiple data formats; the determination module 40 is used to determine the maximum value among the configuration exponent bit widths of the multiple data formats as the intermediate exponent bit width, and to determine the maximum value among the configuration mantissa bit widths of the multiple data formats as the intermediate mantissa bit width.
[0057] In an embodiment of the present application, the data format conversion device can obtain the bit width of the configuration exponent and the bit width of the configuration mantissa of each data format in the preset multiple formats through the acquisition module 30, and then determine the maximum value from the bit widths of the configuration exponents of all formats obtained as the intermediate exponent bit width through the determination module 40, and determine the maximum value from the bit widths of the configuration mantissas of all formats obtained as the intermediate mantissa bit width.
[0058] In the embodiment of the present application, the maximum value of the bit width of the configuration exponent of all formats represents the maximum value range that can be represented by all formats, and the maximum value of the bit width of the configuration mantissa of all formats represents the maximum data precision that can be represented by all formats.
[0059] It is understandable that the data format conversion device can determine the intermediate exponent bit width and intermediate mantissa bit width of the intermediate floating point format according to the maximum numerical range and maximum data precision that can be represented by the preset multiple data formats. In this way, the setting flexibility of the preset multiple data formats can be improved, and the data format conversion device can be implemented using the minimum intermediate exponent bit width and intermediate mantissa bit width, thereby reducing the consumption of hardware resources.
[0060] In the embodiment of the present application, the acquisition module 30 can determine the bit width of the configuration exponent and the bit width of the configuration mantissa according to each data format in the preset multiple data formats.
[0061] In some embodiments of the present application, multiple data formats are preset including a floating-point format, and the acquisition module 30 is further used to use the bit width of the exponent bits of the floating-point format as the configured exponent bit width of the floating-point format; and to determine the configured mantissa bit width of the floating-point format based on the mantissa bit width of the floating-point format and the floating-point integer bit width.
[0062] In the embodiment of the present application, the floating-point format includes exponent bits and mantissa bits. The acquisition module 30 can directly use the bit width of the exponent bits of the floating-point format as the bit width of its configured exponent. Since the mantissa bits of the floating-point format are only decimal bits, and the integer bits are not reflected in the floating-point format, the acquisition module 30 needs to increase the floating-point integer bit width on the basis of the bit width of the mantissa bits to obtain the bit width of its configured mantissa; the floating-point integer bit width is the bit width of the integer bits of the floating-point format. In some embodiments, the integer bit of the floating-point format is 1, and the floating-point integer bit width is 1.
[0063] It can be understood that the data format conversion device can directly extract the bit width of the exponent bits of the floating-point format as the bit width of the configuration exponent, extract the bit width of the mantissa bits and add 1 as the bit width of the configuration mantissa, so that the efficiency of determining the bit width of the configuration exponent and the bit width of the configuration mantissa in the floating-point format can be increased.
[0064] In some embodiments of the present application, multiple data formats are preset including an integer format, and the acquisition module 30 is further used to determine an intermediate bit width based on the total bit width of the integer format; determine the bit width of the configuration exponent of the integer format based on the intermediate bit width; and use the total bit width of the integer format as the bit width of the configuration mantissa of the integer format.
[0065] In an embodiment of the present application, the integer format includes a signed integer format and an unsigned integer format. For any integer format, the acquisition module 30 can use the bit width of all bits of the integer format as the configuration mantissa bit width; for the bit width of all bits of the integer format, take the logarithm with base 2, and then round the logarithm upward to obtain the intermediate bit width. The logarithm of all bit widths of the integer with base 2 is a power of 2, so the logarithm plus 1 as the bit width of the configuration index can characterize the numerical range of the binary integer. Here, for any total bit width, the logarithm with base 2 may not be an integer. In order to make the numerical range of the integer format within the numerical range represented by the bit width of the configuration index, the logarithm needs to be rounded upward.
[0066] In the embodiment of the present application, for any integer format, the bit width int_pw of its configuration index can be determined by formula (3).
[0067]
[0068] Where int_w is the bit width of the integer.
[0069] It can be understood that the data format conversion device can extract all the bit widths of the integer format, use all the bit widths as the bit width of the configuration mantissa, and calculate all the bit widths according to formula (3) to obtain the bit width of the configuration exponent. In this way, the efficiency of determining the bit width of the configuration exponent and the bit width of the configuration mantissa in the integer format can be increased.
[0070] Exemplarily, the preset multiple data formats include FP32 and UNIT32. The exponent bit width of FP32 is 8, and the configured exponent bit width is 8; the mantissa bit width of FP32 is 23, and the configured mantissa bit width is 24. UNIT32 is an integer, and the total bit width is 32, so the configured mantissa bit width is 32, and the configured exponent bit width is 6. Therefore, the intermediate exponent bit width of the intermediate floating-point format of the preset multiple data formats is 8, and the intermediate mantissa bit width is 32.
[0071] based on Figure 1 , Figure 3 FIG. 2 shows the structure of an optional data conversion device. Figure 3 As shown, the first conversion module 10 may include: a special judgment module 101 and an exponent-mantissa conversion module 10-2. The special judgment module 101 is used to judge whether the data to be converted is a preset special number according to the to-be-converted format and the target format of the data to be converted, and obtain a special judgment result; the exponent-mantissa conversion module 10-2 is used to convert the data to be converted according to the intermediate floating-point format, the format of the data to be converted and the special judgment result, and obtain intermediate data.
[0072] In the embodiment of the present application, for different combinations of the formats to be converted and the target formats, the preset special numbers may be the same or different; in this regard, they may be set as needed, and the embodiment of the present application does not limit this. The preset special numbers include floating-point special numbers and integer special numbers. When the format to be converted is a floating-point format, the preset special number is a floating-point special number; when the format to be converted is an integer format, the preset special number is an integer special number.
[0073] In some embodiments, the format to be converted is a floating-point format, the target format is a floating-point format, the preset special number is a first floating-point special number, and the first floating-point special number includes at least one of the following: an abnormal value (denormal number), an infinite number (INF), a non-numeric number (NAN), an absolute value less than the minimum absolute value representable in the target format, and an absolute value greater than the maximum absolute value representable in the target format.
[0074] In some embodiments, the format to be converted is a floating-point format, the target format is an integer format, the preset special number is a second floating-point special number, and the second floating-point special number includes at least one of the following: a non-numeric value, a positive infinite number (+INF), a value greater than the maximum value representable in the target format, a negative infinite number (-INF), and a value less than the minimum value representable in the target format.
[0075] In some embodiments, the format to be converted is an integer format, the target format is a floating point format, the preset special number is a first integer special number, and the first integer special number includes at least one of the following: 0, a maximum positive number greater than the target format can represent, and a minimum negative number less than the target format can represent.
[0076] In some embodiments, the format to be converted is an integer format, the target format is an integer format, the preset special number is a second integer special number, and the second integer special number includes at least one of the following: greater than the maximum value representable in the target format and less than the minimum value representable in the target format.
[0077] In the embodiment of the present application, different floating-point formats correspond to different offset biases, and the offset of the integer format is 0. Therefore, when the data format conversion device converts various data formats into an intermediate floating-point format, it is necessary to consider the difference between the offset of the format to be converted and the offset of the intermediate floating-point format, that is, the conversion offset difference.
[0078] In an embodiment of the present application, after the data format conversion device obtains a special judgment result through the special judgment module 101, when the special judgment result indicates that the data to be converted is a preset special number, the preset special number can be directly used as intermediate data, thereby improving conversion efficiency.
[0079] based on Figure 3 , Figure 4 FIG. 2 shows the structure of an optional data conversion device. Figure 4 As shown, the exponent-mantissa conversion module 10-2 includes: an exponent conversion module 102, which is used to convert the exponent of the data to be converted according to the conversion offset difference between the intermediate floating-point format and the format to be converted, and a special judgment result, to obtain the exponent of the intermediate data; a mantissa conversion module 103, which is used to convert the mantissa of the data to be converted according to the intermediate floating-point format, the format of the data to be converted and the special judgment result, to obtain the mantissa of the intermediate data.
[0080] In an embodiment of the present application, the exponent conversion module 102 can convert the exponent of the data to be converted, and the mantissa conversion module 103 can convert the mantissa of the data to be converted. In this way, the exponent and mantissa of the data to be converted can be converted at the same time through different modules, which can improve the conversion efficiency of the data to be converted.
[0081] based on Figure 4 , Figure 5 FIG. 2 shows the structure of an optional data conversion device. Figure 5As shown, the index conversion module 102 may include: a first index conversion module 1021 and a second index conversion module 1022. The first index conversion module 1021 is used to obtain the to-be-determined index of the intermediate data by converting the offset difference and the to-be-converted data; the second index conversion module 1022 is used to determine the index of the intermediate data according to the special judgment result and the to-be-determined index.
[0082] In the embodiment of the present application, the exponent conversion module 102 can first add the conversion offset difference mbias and the exponent sexp of the data to be converted through the first exponent conversion module 1021 to obtain the to-be-determined exponent texp of the intermediate data, see formula (4), and the conversion offset difference mbias see formula (5); then, through the second exponent module 1022, combined with the special judgment result, select one from the to-be-determined exponent of the intermediate data and the preset special exponent value corresponding to the preset special number as the index of the intermediate data.
[0083] texp = mbias + sexp formula (4)
[0084] mbias=tbias-sbias formula (5)
[0085] Wherein, tbias represents the exponent offset of the intermediate floating-point format, and sbias represents the exponent offset of the format to be converted.
[0086] It can be understood that the data conversion device can determine the to-be-determined index of the intermediate data as the index of the candidate intermediate data through the first index conversion module 1021, and obtain the special judgment result through the special judgment module 101. In this way, the second index conversion module 1022 can quickly determine the index of the intermediate data from the to-be-determined index of the intermediate data and the preset special index value, thereby improving the efficiency of determining the index of the intermediate data.
[0087] In some embodiments of the present application, the second exponent conversion module 1022 is also used to determine the preset special exponent value as the exponent of the intermediate data when the special judgment result indicates that the data to be converted is a preset special number; or to determine the exponent to be determined as the exponent of the intermediate data when the special judgment result indicates that the data to be converted is not a preset special number; the preset special number includes an unformatted floating point number or an integer 0.
[0088] It should be noted that the preset special number and the preset special exponent value corresponding to the preset special number can be set as needed. In the embodiment of the present application, the preset special number includes an unformatted floating point number and an integer 0. Wherein, when the configuration index of the data to be converted is 0, the data to be converted is determined to be an unformatted floating point number; when the format to be converted is an integer and all bits of the data to be converted are 0, the data to be converted is determined to be an integer 0, and the preset special exponent value is 0.
[0089] It is understandable that the second exponent conversion module 1022 can obtain a special judgment result. When the special judgment result indicates that the data to be converted is a non-formatted floating point number or an integer 0, 0 can be directly determined as the exponent to be determined of the intermediate data, without having to determine the exponent to be determined of the intermediate data by the conversion offset difference. In this way, the efficiency of determining the exponent of the intermediate data can be improved.
[0090] In some embodiments, the second index conversion module 1022 may be implemented as a selector for determining the index of the intermediate data from a preset special value and the to-be-determined index of the intermediate data according to the special determination result.
[0091] based on Figure 5 , Figure 6 FIG. 2 shows a schematic diagram of the structure of an optional data conversion device. Figure 6 As shown, the first exponential conversion module 1021 may include: a conversion offset difference acquisition module 10211, an exponent extraction module 10212, and an exponent addition module 10213. The conversion offset difference acquisition module 10211 is used to acquire the conversion offset difference; the exponent extraction module 10212 is used to extract the exponent of the data to be converted; and the exponent addition module 10213 is used to add the exponent of the data to be converted and the conversion offset difference to obtain the exponent to be determined of the intermediate data.
[0092] In an embodiment of the present application, the first exponent conversion module 1021 can obtain the conversion offset difference through the conversion offset difference acquisition module 10211, and extract the exponent of the data to be converted through the exponent extraction module 10212; in this way, the efficiency of the exponent addition module 10213 in obtaining the conversion offset difference and the exponent of the data to be converted can be improved, thereby improving the efficiency of determining the exponent to be determined of the intermediate data.
[0093] In some embodiments, the exponential addition module 10213 can be implemented as an adder; the two inputs of the adder are the exponent of the data to be converted and the conversion offset difference, and the output is the exponent to be determined of the intermediate data. The number of bits of the adder can be set according to actual needs, and the embodiment of the present application is not limited.
[0094] In some embodiments of the present application, the conversion offset difference acquisition module 10211 is also used to determine an offset difference that matches the format of the data to be converted from the preset offset differences as the conversion offset difference; the preset offset includes the difference between the exponent offset of each data format in the preset multiple data formats and the exponent offset of the intermediate floating-point format.
[0095] In the embodiment of the present application, the data conversion device may pre-set the offset difference between the preset multiple data formats and the intermediate floating point format, that is, the preset offset difference. In this way, the data conversion device may select the offset difference matching the format to be converted from the preset offset difference as the conversion offset difference.
[0096] Exemplarily, the preset multiple data formats include: format 1, format 2 and format 3, and the preset offset difference includes mbias1, mbias2 and mbias3; mbias1 represents the conversion offset difference between format 1 and the intermediate floating point format, mbias2 represents the conversion offset difference between format 2 and the intermediate floating point format, and Mbias3 represents the conversion offset difference between format 3 and the intermediate floating point format. If the format to be converted is format 1, the conversion offset difference is mbias1.
[0097] It is understandable that, since the data conversion device stores preset offset differences, the data conversion device can quickly select one of them as the conversion offset difference, thereby improving the efficiency of determining the offset conversion difference.
[0098] In some embodiments of the present application, the conversion offset difference acquisition module 10211 may include: an offset acquisition module and an offset difference determination module. The offset acquisition module is used to acquire the exponent offset of the intermediate floating point format and the exponent offset of the format of the data to be converted; the offset difference determination module is used to use the difference between the exponent offset of the intermediate floating point format and the exponent offset of the format of the data to be converted as the conversion offset difference.
[0099] In an embodiment of the present application, the data format conversion device can obtain the exponent offset tbias of the intermediate floating point format and the exponent offset sbias of the format of the data to be converted through the offset acquisition module, and then use the offset difference determination module to obtain the conversion offset difference mbias according to formula (5) by subtracting the exponent offset sbias of the format of the data to be converted from the exponent offset tbias of the intermediate floating point format.
[0100] It can be understood that even if the preset multiple data formats change, since the data format conversion device can determine the intermediate floating point format, the conversion offset difference can be determined by the offset acquisition module and the offset difference determination module, thereby increasing the flexibility of the data format conversion device in converting data.
[0101] In some embodiments of the present application, the offset acquisition module is further used to determine the exponent offset of the intermediate floating point format according to the intermediate exponent bit width of the intermediate floating point format; and to determine the exponent offset of the format to be converted according to the configured exponent bit width of the format to be converted.
[0102] In the embodiment of the present application, since different exponent bit widths correspond to different exponent offsets, the offset acquisition module can determine its exponent offset according to the data format, see formula (6).
[0103] bias=2 k-1 -1 Formula (6)
[0104] Wherein, k represents the configuration index bit width of the data format.
[0105] The offset acquisition module can determine the exponent offset tbias of the intermediate floating point format according to the intermediate exponent bit width of the intermediate floating point format. The intermediate exponent bit width of the intermediate floating point format is the same as the configured exponent bit width, which is the bit width of the exponent bit of the intermediate floating point format itself. Exemplarily, the intermediate floating point format is FP32, the configured exponent bit width is 8, and its exponent offset tbias is 127; the intermediate floating point format is FP16, the exponent bit width is 5, and its exponent offset tbias is 15.
[0106] The offset acquisition module can determine the exponent offset tbias of the format to be converted according to the configured exponent bit width of the format to be converted. Exemplarily, the format to be converted is UNIT16, the configured exponent bit width is 5, and its exponent offset tbias is 15.
[0107] It can be understood that the data format conversion device can quickly determine the exponent offset corresponding to the data format according to the data format and formula (6), thereby improving the efficiency of converting the offset difference.
[0108] based on Figure 6 , Figure 7 FIG. 2 shows the structure of an optional data conversion device. Figure 7As shown, the mantissa conversion module 103 may include: a first mantissa conversion module 1031 and a second mantissa conversion module 1032. The first mantissa conversion module 1031 is used to perform a first shift process on the mantissa of the data to be converted according to the format to be converted and the intermediate floating point format to obtain the mantissa to be determined of the intermediate data; the bit width of the mantissa to be determined is the bit width of the intermediate mantissa; the second mantissa conversion module 1032 is used to determine the mantissa of the intermediate data according to the special judgment result and the mantissa to be determined.
[0109] In an embodiment of the present application, since the mantissa bit width of the format to be converted and the intermediate mantissa bit width may be different, the data conversion device can perform a first shift processing on the data to be converted through the first mantissa conversion module 1031 to obtain the mantissa of the intermediate data, so that the bit width of the mantissa of the intermediate data is consistent with the bit width of the intermediate mantissa; and then determine whether the mantissa to be determined of the intermediate data is intermediate mantissa data based on a special judgment result through the second mantissa conversion module 1032.
[0110] In an embodiment of the present application, since only the decimal places in the floating-point format data to be converted are reflected in the mantissa places of the data to be converted, in order to keep the numerical value of the floating-point format data to be converted unchanged, it is necessary to perform a first shift processing on the integer 1 and the mantissa places of the floating-point format together. Therefore, the first shift processing method when the data to be converted is in a floating-point format is different from the first shift processing method when the data to be converted is an integer.
[0111] It can be understood that the data conversion device can perform first shift processing in different ways according to whether the data to be converted is in floating point format or integer format, which can improve the accuracy of the mantissa of the intermediate data.
[0112] In some embodiments of the present application, the second mantissa conversion module 1032 is further used to determine the preset special mantissa value as the mantissa of the intermediate data when the special judgment result indicates that the data to be converted is a preset special number; or to determine the to-be-determined mantissa of the intermediate data as the mantissa of the intermediate data when the special judgment result indicates that the data to be converted is not a preset special number; the preset special number includes an unformatted floating point number or an integer 0.
[0113] It should be noted that the preset special number and the preset special mantissa value corresponding to the preset special number can be set as needed. In the embodiment of the present application, the preset special number includes an unformatted floating point number and an integer 0. Wherein, when the configuration index of the data to be converted is 0, the data to be converted is determined to be an unformatted floating point number; when the format to be converted is an integer and all bits of the data to be converted are 0, the data to be converted is determined to be an integer 0, and the preset special mantissa value is 0.
[0114] It is understandable that the second mantissa conversion module 1032 can obtain a special judgment result. When the special judgment result indicates that the data to be converted is an unformatted floating point number or an integer 0, 0 can be directly determined as the mantissa to be determined of the intermediate data, without having to determine the mantissa to be determined of the intermediate data through the first shift process. In this way, the efficiency of determining the mantissa of the intermediate data can be improved.
[0115] based on Figure 7 , Figure 8 FIG. 2 shows the structure of an optional data conversion device. Figure 8 As shown, the first mantissa conversion module 1031 may include: a mantissa extraction module 10311 and a first shift module 10312. The mantissa extraction module 10311 is used to extract the mantissa to be shifted from the data to be converted according to the format to be converted; the mantissa to be shifted is the original code data; the first shift module 10312 is used to perform a first shift process on the mantissa to be shifted according to the format to be converted to obtain the mantissa to be determined.
[0116] In an embodiment of the present application, the mantissa extracted by the data conversion device from the data to be converted through the mantissa extraction module 10311 may be a complement code or an original code, but during the first shift processing, the data conversion device needs to process the original code. Therefore, the data conversion device needs to determine whether the mantissa of the data to be converted is a complement code. If so, the mantissa of the data to be converted needs to be converted into the original code to obtain the mantissa to be shifted.
[0117] In the embodiment of the present application, after obtaining the mantissa to be shifted, the data conversion device can perform a first shift process on the mantissa to be shifted through the first shift module 10312 to obtain the mantissa to be determined of the intermediate data. In some embodiments, the first shift module 10312 can be implemented as a shifter, the input of the shifter is the mantissa to be shifted, and the shifter is used to perform a first shift process on the mantissa to be shifted and output the mantissa to be determined of the intermediate data.
[0118] In some embodiments of the present application, the format of the data to be converted is a floating point format; the first shift module 10312 is also used to concatenate the high bits of the mantissa to be shifted with the integer bits of the floating point format to obtain a floating point decimal; then the floating point decimal is used as the highest bit of the mantissa to be determined, and the remaining low bits are filled with 0.
[0119] In the embodiment of the present application, the format of the data to be converted is a floating point format. The first shift module 10312 needs to concatenate the highest bit of the shifted mantissa with the integer bit 1 of the floating point format to obtain a decimal in the floating point format, that is, a floating point decimal; then, the floating point decimal is used as the highest bit of the mantissa to be determined of the intermediate data, and the remaining vacancies are filled with 0, see Fig. 9 After the first shift process, the integer bit 1 of the floating point format will be located at the highest bit of the mantissa to be determined of the intermediate data.
[0120] It can be understood that, through the first shift processing of the data to be converted in the floating-point format, the mantissa representing the mantissa to be determined of the intermediate data can be made the same as the numerical value represented by the mantissa of the data to be converted, thereby improving the accuracy of the mantissa of the intermediate data converted from the floating-point format to the intermediate floating-point format.
[0121] In some embodiments of the present application, the format of the data to be converted is an integer format; the first shift module 10312 is further used to use the mantissa to be shifted as the lowest bit of the mantissa to be determined, and fill the remaining high bits with 0.
[0122] In the embodiment of the present application, the format of the data to be converted is an integer format, and the mantissa of the integer format itself can represent the value of its mantissa. Therefore, the first shift module 10312 can directly use the mantissa of the data to be converted as the lowest bit of the mantissa to be determined of the intermediate data, and fill the remaining high bits with 0, see Fig. 9 After the first shift process, the value of the to-be-determined mantissa of the intermediate data is the same as the value in the integer format.
[0123] It can be understood that, through the first shift processing of the data to be converted in integer format, the mantissa representing the mantissa to be determined of the intermediate data can be made the same as the numerical value represented by the mantissa of the data to be converted, thereby improving the accuracy of the mantissa of the intermediate data converted from the integer format to the intermediate floating point format.
[0124] Exemplarily, the preset multiple data formats include FP32 and SINT32, and the intermediate mantissa bit width is 32. The first shift module 10312 performs a first shift processing on the mantissa of FP32 as follows: Fig.10 As shown, the mantissa to be shifted includes the integer bit 1 and the 23-bit combined number of the mantissa of FP32, totaling 24 bits; the high 24 bits of the mantissa to be determined of the intermediate data are the mantissa to be shifted, and the remaining 8 low bits are filled with 0. The first shift module 10312 performs the first shift processing on the mantissa of SINT32 as shown in Fig.11 As shown, the low bit of the to-be-determined mantissa of the intermediate data is the 31-bit mantissa of SINT32, and the highest bit is padded with 0.
[0125] It can be understood that the data conversion device can obtain the mantissa to be shifted of the original code through the mantissa extraction module, and then perform the first shift processing on the mantissa to be shifted; in this way, the accuracy of the mantissa of the intermediate data can be improved.
[0126] based on Figure 8 , Fig.12 FIG. 2 shows the structure of an optional data conversion device. Fig.12As shown, the mantissa extraction module 10311 may include: a positive processing module 10311-1 and an extracted mantissa selection module 10311-2. The positive processing module 10311-1 is used to perform absolute value processing on the mantissa of the data to be converted to obtain a positive mantissa; the extracted mantissa selection module 10311-2 is used to determine the mantissa of the data to be converted as the mantissa to be shifted when the positive and negative properties indicate that the data to be converted is a positive number; or determine the positive mantissa as the mantissa to be shifted when the positive and negative properties indicate that the data to be converted is a negative number.
[0127] In the embodiment of the present application, the mantissa extraction module 10311 can perform absolute value processing on the mantissa of the data to be converted through the positive processing module 10311-1 to obtain a positive mantissa. If the data to be converted is a negative number and the mantissa of the data to be converted is a complement code, the positive mantissa is the original code; if the data to be converted is a positive number, the mantissa of the data to be converted remains unchanged and is the original value.
[0128] In the embodiment of the present application, the mantissa extraction module 10311 can select one from the positive mantissa and the mantissa of the data to be converted as the mantissa to be shifted according to the positive and negative properties of the data to be converted by extracting the mantissa selection module 10311-2. When the data to be converted is a negative number, the positive mantissa is selected as the mantissa to be shifted; when the data to be converted is a positive number, the mantissa of the data to be converted itself is selected as the mantissa to be shifted.
[0129] It can be understood that, through the positive processing module 10311-1 and the mantissa selection module 10311-2, the mantissa extraction module 10311 can output a uniquely determined mantissa to be shifted according to the positive and negative properties of the data to be converted.
[0130] based on Fig.12 , Fig.13 FIG. 2 shows the structure of an optional data conversion device. Fig.13 As shown, the second conversion module 20 includes: an exponent calculation module 201, a mantissa calculation module 202 and a restoration module 203. The exponent calculation module 201 is used to add the exponent influence value generated in the mantissa calculation process to the exponent of the intermediate data to obtain the intermediate restoration index; the mantissa calculation module 202 is used to perform a second shift process on the mantissa of the intermediate data according to the format of the data to be converted, the intermediate data and the target format to obtain the intermediate restoration mantissa; the bit width of the intermediate restoration mantissa is the same as the bit width of the mantissa in the target format; the restoration module 203 is used to restore the mantissa value of the intermediate restoration exponent and the intermediate restoration mantissa combined according to the target format and the special judgment result to obtain the target format data.
[0131] In the embodiment of the present application, the target format is an integer format, and the mantissa bit width of the target format is the bit width of the other bits of the integer format except the sign bit. The target format is a floating point format, and the mantissa bit width of the target format is the mantissa bit width of the floating point format plus 1.
[0132] In the embodiment of the present application, the mantissa calculation module 202 performs a second shift process on the mantissa of the intermediate data, and can determine the value that the mantissa of the intermediate data can represent according to the target format. It should be noted that when the mantissa calculation module 202 performs the second shift process, the exponent size of the intermediate data will be affected; for example, when the second shift process is to shift the mantissa of the intermediate data to the left, the exponent of the intermediate data will be reduced, and when the second shift process is to shift the mantissa of the intermediate data to the right, the exponent of the intermediate data will be increased. Alternatively, in the second shift process, when it is necessary to intercept the mantissa width of the target format from the mantissa of the intermediate data, the rounding process may produce a mantissa overflow, which will also cause the exponent of the intermediate data to increase. Therefore, when the mantissa calculation module 202 performs the second shift process on the mantissa of the intermediate data, the exponent influence value can be determined according to the change of the mantissa digits, and the exponent influence value can be positive or negative. In this way, the exponent calculation module 201 can add the exponent influence value and the exponent of the intermediate data to obtain the intermediate restoration index.
[0133] In the embodiment of the present application, the restoration module 203 can determine the numerical value of the data to be converted by the exponent of the intermediate data and the mantissa of the intermediate data, and then represent the data to be converted according to the target format to obtain the target format data. It should be noted that, in the case where the special judgment result of the data to be converted indicates that the data to be converted is a special number, the corresponding special number can be
[0134] It is understandable that the second conversion module 20 can calculate the exponent of the intermediate data and the mantissa of the intermediate data respectively through the exponent calculation module 201 and the mantissa calculation module 202, which can improve the calculation efficiency of the intermediate restored exponent and the intermediate restored mantissa.
[0135] In some embodiments of the present application, the exponent impact value includes: a leading shift value and a mantissa overflow value; the leading shift value represents the number of leading zeros of the mantissa of the data to be converted based on the intermediate mantissa bit width; the mantissa overflow value represents the overflow value of the mantissa of the intermediate data represented by the target format.
[0136] In the embodiment of the present application, when the format to be converted is an integer format, since the high bit may be padded with 0 when performing the first shift process, the high bit of the mantissa in the integer format may also have 0, resulting in a leading 0 in the high bit of the mantissa of the intermediate data. Since the leading 0 does not affect the size of the mantissa value, the leading 0 can be removed to make the first high bit a valid number, thereby obtaining the number of valid bits that affect the size of the mantissa in the mantissa of the intermediate data. When the format to be converted is a floating point format, the highest bit is 1 and the number of leading 0s is 0.
[0137] In the embodiment of the present application, since the bit width of the intermediate restored mantissa may be different from the mantissa bit width of the target format, the mantissa calculation module 202 may intercept the number of the mantissa bit width of the target format from the intermediate restored mantissa, and then round the number according to the preset rounding method. During the rounding process, the number may need to be added by 1, resulting in an overflow value of the number, which is the mantissa overflow value.
[0138] In the embodiment of the present application, both the mantissa overflow value and the leading shift value will affect the size of the exponent. The exponent calculation module adjusts the exponent of the intermediate data according to the exponent impact value, which can improve the numerical accuracy of the intermediate restored exponent.
[0139] based on Fig.13 , Fig.14 FIG. 2 shows the structure of an optional data conversion device. Fig.14 As shown, the mantissa calculation module 202 may include: a leading determination module 2021, a second shift module 2022 and a mantissa rounding module 2023. The leading determination module 2021 is used to determine the number of leading 0s from the mantissa of the intermediate data to obtain a leading shift value; the second shift module 2022 is used to perform a second shift process on the mantissa of the intermediate data according to the leading shift value, the intermediate floating point format and the target format to obtain a second shifted mantissa; the second shifted mantissa includes a truncated mantissa and a redundant mantissa; the truncated mantissa is located at a high position of the second shifted mantissa, and the bit width is the same as the bit width of the intermediate mantissa; the mantissa rounding module 2023 is used to perform a rounding operation according to the redundant mantissa and the truncated mantissa in accordance with the first rounding mode to obtain an intermediate restored mantissa and a mantissa overflow value.
[0140] In an embodiment of the present application, the leading determination module 2021 can determine the number of leading 0s from the mantissa of the intermediate data. In some embodiments, the leading determination module 2021 can identify the numerical value in the mantissa of the intermediate data, read the numerical value of the continuous 0 starting from the 0 of the highest bit, and obtain the leading shift value. In some embodiments, the leading determination module 2021 can be sequentially bitwise or from the highest bit to the low bit, and the number of digits with the result of 0 is used as the leading shift value. In some embodiments, the leading determination module 2021 can be implemented as a leading 0 detection device (Leading-Zero Detector, LZD). In the case where the data src to be converted is all 0, any value can be returned.
[0141] In the embodiment of the present application, the second shift module 2022 can remove the leading 0 of the mantissa of the intermediate data, and then intercept the mantissa bit width of the target format according to the difference between the intermediate floating point format and the target format, to obtain the intercepted mantissa of the second shifted mantissa, and the remaining low-order bits are used as the redundant mantissa of the second shifted mantissa. In some embodiments, the second shift module 2022 can be implemented as a bidirectional shift device, and the leading 0 can be removed by left shift; after right shift, the mantissa in the window is the intercepted mantissa, and the mantissa outside the window is the redundant mantissa.
[0142] Exemplarily, the mantissa bit width of the target format is 3, and the mantissa of the intermediate data is 001011, then the second shift mantissa is 1011, the truncated mantissa is 101, and the redundant mantissa is 1.
[0143] In the embodiment of the present application, the mantissa rounding module 2023 can round the redundant mantissa and the truncated mantissa, use the rounded truncated mantissa as the intermediate restored mantissa, and use the overflow bit value of the rounded truncated mantissa as the mantissa overflow value. The first rounding method can be rounding to even or rounding to an even number.
[0144] It should be noted that if the truncated mantissa after rounding does not overflow, the mantissa overflow value is 0.
[0145] For example, the truncated mantissa is 101, the redundant mantissa is 1, and the first rounding mode is rounding to the nearest integer. The mantissa rounding module 2023 can determine that the intermediate restored mantissa is 110, and the mantissa overflow value is 0.
[0146] It can be understood that the mantissa calculation module 202 can determine the leading shift value through the leading determination module 2021, perform the second shift processing according to the leading shift value through the second shift module 2022, obtain the truncated mantissa and the redundant mantissa, and then determine the intermediate restored mantissa and the mantissa overflow value through the mantissa rounding module 2023. In this way, the leading shift value and the mantissa overflow value, that is, the exponent influence value, can be determined while calculating the intermediate restored mantissa, which can improve the function of the mantissa calculation module 202, and further improve the accuracy of the intermediate restored mantissa and the intermediate restored exponent.
[0147] based on Fig.14 , Fig.15 FIG. 2 shows the structure of an optional data conversion device. Fig.15 As shown, the mantissa rounding module 2023 may include: a rounding detection module 20231 and a mantissa addition module 20232. The rounding detection module 20231 is used to determine the round-up value according to at least one of the value of the truncated mantissa and the value of the redundant mantissa in accordance with the first rounding mode; the round-up value is used to represent the increase in the value of the truncated mantissa; the mantissa addition module 20232 is used to sum the value of the truncated mantissa and the round-up value to obtain the intermediate restored mantissa and the mantissa overflow value.
[0148] In the embodiment of the present application, the first rounding mode is rounding to the nearest integer, and the rounding detection module 20231 can determine the rounding value according to the value of the redundant mantissa. The first rounding mode is rounding to an even number, and the rounding detection module 20231 can determine the rounding value according to the value of the truncated mantissa and the redundant mantissa.
[0149] In some embodiments, the mantissa addition module 20232 is implemented as a circuit consisting of an adder, a selector and an overflow detection unit. Here, the number of bits of the adder and the selector can be set as needed, and the embodiment of the present application is not limited. The selector determines the mantissa overflow value according to the detection result of the overflow detection unit. Exemplarily, the data to be converted is FP32, and the 23-bit mantissa bits are all 1. The overflow detection unit can determine that the mantissa overflow value is 1 when the rounded-up value is 1, otherwise it is 0; the selector is used to select 1 or 0 as the mantissa overflow value.
[0150] It is understandable that after the rounding detection module 20231 determines the rounded-up value, the rounded-up value can be added to the value of the truncated mantissa by the mantissa addition module 20232 to obtain the intermediate restored mantissa. In this way, the hardware processing method for determining the intermediate restored mantissa can be simplified.
[0151] In some embodiments of the present application, the first rounding method is rounding up, and the rounding detection module 20231 can determine that the rounded-up value is 1 when the value of the preset high bit of the redundant mantissa is greater than the preset rounding threshold; or, when the value of the preset high bit of the redundant mantissa is less than the preset rounding threshold, determine that the rounded-up value is 0.
[0152] In an embodiment of the present application, the preset rounding threshold can be determined based on the number of preset high-order bits of the redundant mantissa, which is not limited in the embodiment of the present application.
[0153] Exemplarily, the redundant mantissa is 10. The preset number of high bits is 1, and the preset rounding threshold is 1. The rounding detection module 20231 can compare the highest bit "1" of the redundant mantissa with the preset rounding threshold, and obtain a comparison result that the highest bit "1" of the redundant mantissa is the same as the preset rounding threshold, thereby determining that the rounded-up value is 1.
[0154] It is understandable that the rounding detection module 20231 can determine the round-up value through the redundant mantissa to implement the rounding method of rounding to the nearest integer.
[0155] In some embodiments of the present application, the first rounding method is rounding to an even number, and the rounding detection module 20231 is also used to determine that the rounded-up value is 1 when the value of the highest two bits of the redundant mantissa is greater than a preset rounding threshold; or, when the value of the highest two bits of the redundant mantissa is less than the preset rounding threshold, determine that the rounded-up value is 0; or, when the value of the highest two bits of the redundant mantissa is equal to the preset threshold and the value of the truncated mantissa is an even number, determine that the rounded-up value is 0; or, when the value of the highest two bits of the redundant mantissa is equal to the preset threshold and the value of the truncated mantissa is an odd number, determine that the rounded-up value is 1.
[0156] Exemplarily, the preset rounding threshold is 10. If the truncated mantissa is 10 and the redundant mantissa is 10, the rounding detection module 20231 can determine that the rounded-up value is 0. If the truncated mantissa is 10 and the redundant mantissa is 11, the rounding detection module 20231 can determine that the rounded-up value is 1. If the truncated mantissa is 01 and the redundant mantissa is 10, the rounding detection module 20231 can determine that the rounded-up value is 1.
[0157] In some embodiments, the rounding detection module 20231 can determine whether the bit after the highest bit of the redundant mantissa is 0. If so, the rounding-up value is determined according to whether the lowest bit of the truncated mantissa is 0; if the lowest bit of the truncated mantissa is 0, the rounding-up value is determined to be 0; if the lowest bit of the truncated mantissa is 1, the rounding-up value is determined to be 1. If the bit after the highest bit of the redundant mantissa is not 0, the rounding-up value is determined to be 1.
[0158] It is understandable that the rounding detection module 20231 can determine the rounding-up value by truncating the value of the mantissa to see whether it is an even number, thereby implementing the rounding method of rounding to an even number.
[0159] In some embodiments of the present application, the second shift module 2022 is also used to determine the second shift value according to the leading shift value, the intermediate floating-point format and the target format; when the second shift value is a positive value, the second shift processing is a left shift; when the second shift value is a negative value, the second shift processing is a right shift; according to the second shift value, the mantissa of the intermediate data is subjected to a second shift processing to obtain the second shift mantissa of the original code; the second shift mantissa is determined according to the positive and negative properties of the data to be converted and the second shift mantissa of the original code.
[0160] In the embodiment of the present application, the second shift module 2022 can determine the second shift value according to the leading shift value, the intermediate floating point format and the target format; then shift the mantissa of the intermediate data according to the second shift value to obtain the second shift mantissa of the original code, and finally process the second shift mantissa of the original code according to the positive and negative properties of the data to be converted to obtain the second shift mantissa. If the data to be converted is a positive number, the second shift mantissa is the original code, and if the data to be converted is a negative number, the second shift mantissa is the complement code.
[0161] It can be understood that determining the shift direction of the second shift by the positive and negative properties of the second shift value can improve the intelligence of hardware processing.
[0162] In some embodiments of the present application, the second shift module 2022 is also used to use the second shift mantissa of the original code as the second shift mantissa when the positive and negative properties of the data to be converted are positive numbers; or, when the positive and negative properties of the data to be converted are negative numbers, use the complement of the second shift mantissa of the original code as the second shift mantissa.
[0163] It can be understood that since the data processed previously are all original code data, and if the target format is a signed format, the mantissa of the floating-point format or the number of bits in the integer format except the sign bit needs to be represented by a complement code. Here, the second shifted mantissa is determined according to the format of the data to be converted, which can improve the accuracy of data processing.
[0164] It should be noted that the second shift value is a signed integer. When the sign of the second shift value indicates that the second shift value is a negative number, the second shift processing is a right shift; when the sign of the second shift value indicates that the second shift value is a positive number, the second shift processing is a left shift. For different target formats, the second shift module 2022 determines the second shift value in different ways.
[0165] In some embodiments, when the target format is a floating point format, the second shift module 2022 can determine the second shift value according to the leading shift value, the intermediate mantissa bit width and the mantissa bit width of the target format. Wherein, the leading shift value represents the number of left shifts. By left shifting, the leading shift value high bit 0 in the intermediate mantissa bit width can be removed, and then the number of mantissa bit widths of the target format can be intercepted from the highest bit of the remaining number of bits as the intercepted mantissa. Here, the interception process is equivalent to right shifting the remaining number of bits, and the number shifted out to the right is the redundant mantissa, and the number of the remaining mantissa other than the redundant mantissa is the intercepted mantissa.
[0166] In some embodiments of the present application, the target format is a floating point format; the second shift module 2022 is used to use the leading shift value lzd to subtract the difference between the intermediate mantissa bit width tmat_w and the bit width rmat_w of the target format data to obtain the second shift value rmat_shf_val, see formula (7).
[0167] rmat_shf_val = lzd-(tmat_w - rmat_w) Formula (7)
[0168] Among them, the difference between the intermediate mantissa bit width tmat_w and the target format data bit width rmat_w is the number of right shift bits in the truncation process, the second shift value rmat_shf_val is the difference between the left shift bit lzd and the right shift bit, and the right shift bit is the number of redundant mantissa bits.
[0169] Exemplarily, if the mantissa of the intermediate data is 0010010, the leading shift value is 2, and the intermediate mantissa bit width tmat_w is 7. If the bit width rmat_w of the target format data is 4, the second shift value is -1; that is, the second shift module 2022 needs to right-shift the mantissa 0010010 of the intermediate data by 1 bit to obtain the truncated mantissa 1001 and the redundant mantissa 0, and determine that the intermediate restored mantissa is 1010 by rounding to an even number.
[0170] It can be understood that the intermediate floating-point format mantissa can be converted into an intermediate restored mantissa of a floating-point format with the integer bit 1 at the highest bit by formula (7). In this way, as long as the intermediate restored mantissa of the floating-point format is restored to the target format, the format conversion of the data to be converted can be achieved. Since the intermediate data of the floating-point format is represented by any floating-point format, it can be implemented by a hardware circuit in the related art, which facilitates the hardware implementation of the data format conversion device and can increase the diversity of the target format.
[0171] In some embodiments, when the target format is an integer format, the second shift module 2022 can determine the second shift value according to the exponent of the intermediate data, the offset of the intermediate floating point format, and the mantissa bit width of the target format. Since the integer format does not involve the exponent bit, the second shift module 2022 needs to clear the exponent by shifting the mantissa, and the mantissa after clearing the exponent also needs to truncate the low bit or fill the low bit with 0 to achieve conversion to the mantissa of the target format.
[0172] In some embodiments of the present application, the target format is an integer format; the second shift module 2022 is further used to obtain a second shift value using the difference between the exponent of the intermediate data and the exponent offset of the intermediate floating-point format, and the intermediate mantissa bit width.
[0173] In the embodiment of the present application, the difference between the exponent texp of the intermediate data and the exponent offset tbias of the intermediate floating point format is the true value of the exponent of the intermediate data, that is, the number of left shifts. The difference between the intermediate mantissa bit width tmat_w and 1 is the number of right shifts. The right shift process is to move the highest integer bit of the intermediate floating point format to the lowest bit of the intermediate restored mantissa, see Fig.16 Therefore, the second shift value rmat_shf_val is the difference between the left shift number and the right shift number, see formula (8).
[0174] rmat_shf_val = texp-tbias-(tmat_w - 1) Formula (8)
[0175] It can be understood that the intermediate floating point format value can be expressed in integer format through formula (8), thereby realizing the conversion of the intermediate floating point format into integer format. In this way, as long as the intermediate restoration mantissa of the integer format is restored to the target format, the format conversion of the data to be converted can be completed. Since the intermediate restoration mantissa is converted into any integer format, the hardware circuit in the related art can be used to realize it, which facilitates the hardware implementation of the data format conversion device and can improve the diversity of the target format.
[0176] based on Fig.15 , Fig.17 FIG. 2 shows the structure of an optional data conversion device. Fig.17As shown, the restoration module 203 may include: a floating point restoration module 2031, an integer restoration module 2032 and a target format selection module 2033. Among them, the floating point restoration module 2031 is used to restore the combined number of the intermediate restoration exponent and the intermediate restoration mantissa to floating point format data according to the symbol value, special judgment result and target format of the intermediate data; the integer restoration module 2032 is used to restore the intermediate restoration mantissa to integer format data according to the symbol value, special judgment result and target format of the intermediate data; the target format selection module 2033 is used to determine the floating point format data as the target format data when the target format is a floating point format; or, when the target format is an integer format, determine the integer format data as the target format data. In some embodiments, the target format selection module can be set as a selector for selecting one from the integer format data and the floating point format data as the target format data. Here, the number of bits of the selector can be set as needed, and the embodiment of the present application is not limited.
[0177] In an embodiment of the present application, the floating-point restoration module 2031 can restore the merged number of the intermediate restoration exponent and the intermediate restoration mantissa to a target format, and the target format can be any one of the floating-point formats in a plurality of preset data formats. Here, the floating-point restoration module 2031 also needs to restore the merged number according to the sign value of the intermediate data. In the case where the sign value of the intermediate data indicates that the intermediate data is a negative number, the mantissa of the floating-point format data needs to be a complement number. The floating-point restoration module 2031 also needs to determine the floating-point format data as a floating-point result value matching the floating-point special number when the special judgment result indicates that the data to be converted is a floating-point special number.
[0178] Table 1 shows the floating point result value corresponding to the first floating point special number. Table 2 shows the floating point result value corresponding to the second floating point special number.
[0179] Table 1
[0180] The first floating point special number Floating point result value Denormal number ±0 Infinity (INF) ±INF Not a Number (NAN) NAN The absolute value is less than the smallest absolute value representable in the target format ±0 The absolute value is greater than the maximum representable absolute value in the target format ±INF
[0181] Table 2
[0182] The second floating point special number Floating point result value Not a Number (NAN) 0 Positive infinity (+INF) The maximum value representable in the target format Negative infinity (-INF) The smallest value representable in the target format Larger than the maximum representable value in the target format The maximum value representable in the target format is smaller than the smallest value representable in the target format The smallest value representable in the target format
[0183] In the embodiment of the present application, when the target format is an integer format, the integer restoration module 2032 can restore the intermediate restoration mantissa to the target format, and the target format can be any floating point format in a plurality of preset data formats. Here, the integer restoration module 2032 also needs to restore the merged number according to the sign value of the intermediate data. When the sign value of the intermediate data indicates that the intermediate data is a negative number, the mantissa of the integer format data needs to be a complement number. The integer restoration module 2032 also needs to determine the integer format data as an integer result value matching the integer special number when the special judgment result indicates that the data to be converted is an integer special number.
[0184] Table 3 shows the integer result value corresponding to the first integer special number. Table 4 shows the integer result value corresponding to the second integer special number.
[0185] Table 3
[0186] The first special integer Integer result value 0 0 Larger than the largest positive number representable in the target format INF Less than the smallest negative number representable in the target format INF
[0187] Table 4
[0188] The second integer special number Integer result value Larger than the largest positive number representable in the target format The maximum value representable in the target format Less than the smallest negative number representable in the target format The smallest value representable in the target format
[0189] It is understandable that after the conversion processing is performed by the floating point restoration module 2031 and the integer restoration module 2032 respectively, the target format selection module 2033 can select one output from the numbers obtained by the above two modules, which can improve the restoration processing efficiency of the restoration module 203.
[0190] In some embodiments of the present application, the floating-point restoration module 2031 is also used to determine the floating-point result value corresponding to the floating-point special number as the target format data when the special judgment result indicates that the data to be converted is a floating-point special number; the floating-point restoration module 2031 is also used to perform a first floating-point restoration process on the merged number of the intermediate restoration exponent and the intermediate restoration mantissa according to the sign value of the intermediate data to obtain floating-point format data in the first floating-point format when the special judgment result indicates that the data to be converted is not a floating-point special number and the target format is a first floating-point format.
[0191] In the embodiment of the present application, the floating point restoration module 2031 can first determine whether the special judgment result indicates that the data to be converted is a floating point special number. If so, the floating point result value corresponding to the floating point special number is directly determined as floating point format data; otherwise, according to the sign value of the intermediate data, the first floating point restoration process is performed on the merged number to obtain a floating point format number in a first floating point format. The first floating point format is one of the floating point formats; the first floating point format is one of the preset multiple data formats.
[0192] It can be understood that the floating-point restoration module 2031 first determines whether the special judgment result represents that the data to be converted is a floating-point special number. When the special judgment result represents that the data to be converted is a floating-point special number, the floating-point result value corresponding to the floating-point special number can be directly determined as floating-point format data; without restoring the merged number, the restoration efficiency of the floating-point restoration module 2031 can be improved.
[0193] In some embodiments of the present application, the integer second conversion module 2032 is also used to determine the integer result value corresponding to the integer special number as the target format data when the special judgment result indicates that the data to be converted is an integer special number; the integer second conversion module 2032 is also used to perform a first integer restoration process on the combined value of the intermediate restoration exponent and the intermediate restoration mantissa according to the sign value of the intermediate data to obtain integer format data in the first integer format when the special judgment result indicates that the data to be converted is not an integer special number and the target format is the first integer format.
[0194] In the embodiment of the present application, the integer restoration module 2032 can first determine whether the special judgment result indicates that the data to be converted is an integer special number. If so, the integer result value corresponding to the integer special number is directly determined as integer format data; otherwise, according to the sign value of the intermediate data, the intermediate restoration mantissa is subjected to a first integer restoration process to obtain an integer format number in a first integer format. The first integer format is one of the integer formats; the first integer format is one of the preset multiple data formats.
[0195] It can be understood that since the integer restoration module 2032 first determines whether the special judgment result represents that the data to be converted is an integer special number, when the special judgment result represents that the data to be converted is an integer special number, the integer result value corresponding to the integer special number can be directly determined as integer format data; without restoring the intermediate restoration mantissa, the restoration efficiency of the integer restoration module 2032 can be improved.
[0196] Based on the above data conversion device, Fig.18 An optional data conversion method is shown, such as Fig.18 As shown, the method may include:
[0197] S101. Convert the data to be converted in any one of a plurality of preset data formats into intermediate data in an intermediate floating-point format; the bit width of the intermediate exponent of the intermediate floating-point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to the plurality of preset formats; the bit width of the intermediate mantissa of the intermediate floating-point format is the maximum value of the bit widths of a plurality of configuration mantissas corresponding to the plurality of preset data formats; the bit width of the configuration exponent of each data format is used to characterize the numerical range of the data format; the bit width of the configuration mantissa of each data format is used to characterize the data precision of the data format.
[0198] S102 . Convert the intermediate data into target format data according to a conversion method that matches the target format data; the target format of the target format data is any one of a plurality of preset data formats.
[0199] In some embodiments, before converting the data to be converted in any one of the preset multiple data formats into intermediate data in an intermediate floating-point format in S101, the method further includes: acquiring, through an acquisition module, the bit width of a configuration exponent and the bit width of a configuration mantissa of each data format in the preset multiple data formats; determining, through a determination module, the maximum value among the bit widths of the configuration exponents of the multiple data formats as the intermediate exponent bit width, and determining, through a determination module, the maximum value among the bit widths of the configuration mantissas of the multiple data formats as the intermediate mantissa bit width.
[0200] In some embodiments, the preset multiple data formats include a floating-point format; the method further includes: using the bit width of the exponent bits of the floating-point format as the configured exponent bit width of the floating-point format through the acquisition module; and determining the configured mantissa bit width of the floating-point format based on the mantissa bit width of the floating-point format and the floating-point integer bit width.
[0201] In some embodiments, the preset multiple data formats include an integer format; the method also includes: determining an intermediate bit width based on the total bit width of the integer format through the acquisition module; determining the bit width of the configuration exponent of the integer format based on the intermediate bit width; and using the total bit width of the integer format as the bit width of the configuration mantissa of the integer format.
[0202] In some embodiments, the method of converting the data to be converted in any one of a plurality of preset data formats into intermediate data in an intermediate floating-point format in S101 also includes: obtaining a special judgment result by a special judgment module based on the format to be converted of the data to be converted and the target format and judging whether the data to be converted is a preset special number; and obtaining the intermediate data by an exponent-mantissa conversion module based on the intermediate floating-point format, the format of the data to be converted and the special judgment result.
[0203] In some embodiments, the method further includes: converting the exponent of the data to be converted by an exponent conversion module according to the conversion offset difference between the intermediate floating-point format and the format to be converted, and the special judgment result, to obtain the exponent of the intermediate data; converting the mantissa of the data to be converted by a mantissa conversion module according to the intermediate floating-point format, the format of the data to be converted and the special judgment result, to obtain the mantissa of the intermediate data.
[0204] In some embodiments, the method further includes: obtaining, through a first index conversion module, a to-be-determined index of the intermediate data through the conversion offset difference and the to-be-converted data; and determining, through a second index conversion module, the index of the intermediate data according to the special judgment result and the to-be-determined index.
[0205] In some embodiments, the method further includes: obtaining the conversion offset difference through a conversion offset difference acquisition module; extracting the exponent of the data to be converted through an exponent extraction module; and adding the exponent of the data to be converted and the conversion offset difference through an exponent addition module to obtain the index to be determined.
[0206] In some embodiments, the method further includes: determining, through the conversion offset difference acquisition module, an offset difference that matches the format of the data to be converted from the preset offset differences as the conversion offset difference; the preset offset includes the difference between the exponent offset of each data format in the preset multiple data formats and the exponent offset of the intermediate floating-point format.
[0207] In some embodiments, the method further includes: obtaining, through an offset acquisition module, an exponent offset of the intermediate floating-point format and an exponent offset of the format to be converted; and using, through an offset difference determination module, a difference between the exponent offset of the intermediate floating-point format and the exponent offset of the format of the data to be converted as the conversion offset difference.
[0208] In some embodiments, the method further includes: determining, by the offset acquisition module, the exponent offset of the intermediate floating-point format according to the intermediate exponent bit width of the intermediate floating-point format; and determining the exponent offset of the format to be converted according to the configured exponent bit width of the format to be converted.
[0209] In some embodiments, the method further includes: through the second exponent conversion module, when the special judgment result indicates that the data to be converted is a preset special number, determining the preset special exponent value as the exponent of the intermediate data; or, when the special value judgment result indicates that the data to be converted is not the preset special number, determining the to-be-determined exponent as the exponent of the intermediate data; the preset special number includes an unformatted floating point number or an integer 0.
[0210] In some embodiments, the method further includes: performing a first shift processing on the mantissa of the data to be converted according to the format to be converted and the intermediate floating-point format through a first mantissa conversion module to obtain a mantissa to be determined for the intermediate data; the bit width of the mantissa to be determined is the bit width of the intermediate mantissa; and determining the mantissa of the intermediate data according to the special judgment result and the mantissa to be determined through a second mantissa conversion module.
[0211] In some embodiments, the method further includes: extracting the mantissa to be shifted from the data to be converted through a mantissa extraction module according to the format to be converted; the mantissa to be shifted is the original code data; and performing a first shift processing on the mantissa to be shifted according to the format to be converted through a first shift module to obtain the mantissa to be determined.
[0212] In some embodiments, the method further includes: taking the absolute value of the mantissa of the data to be converted through a positive processing module to obtain a positive mantissa; extracting the mantissa selection module, when the positive and negative properties indicate that the data to be converted is a positive number, determining the mantissa of the data to be converted as the mantissa to be shifted; or, when the positive and negative properties indicate that the data to be converted is a negative number, determining the positive mantissa as the mantissa to be shifted.
[0213] In some embodiments, the format of the data to be converted is a floating point format; the method also includes: through the first shift module, the highest bit of the mantissa to be shifted is spliced with the integer bit of the floating point format to obtain a floating point decimal; then the decimal mantissa is used as the highest bit of the mantissa to be determined, and the remaining low bits are filled with 0.
[0214] In some embodiments, the format of the data to be converted is an integer format; the method further includes: using the first shift module to use the mantissa to be shifted as the lowest bit of the mantissa to be determined, and filling the remaining high bits with 0.
[0215] In some embodiments, the method further includes: through the second mantissa conversion module, when the special judgment result indicates that the data to be converted is a preset special number, determining the preset special mantissa value as the mantissa of the intermediate data; or, when the special judgment result indicates that the data to be converted is not the preset special number, determining the mantissa to be determined as the mantissa of the intermediate data; the preset special number includes an unformatted floating point number or an integer 0.
[0216] In some embodiments, the method further includes: adding the exponent influence value generated in the mantissa calculation process to the exponent of the intermediate data through an exponent calculation module to obtain an intermediate restored index; performing a second shift processing on the mantissa of the intermediate data according to the format of the data to be converted, the intermediate data, and the target format through the mantissa calculation module to obtain an intermediate restored mantissa; the bit width of the intermediate restored mantissa is the same as the bit width of the mantissa of the target format; performing a restoration processing on the mantissa value of the intermediate restored exponent and the intermediate restored mantissa combined according to the target format and the special judgment result through a restoration module to obtain the target format data.
[0217] In some embodiments, the exponent impact value includes: a leading shift value and a mantissa overflow value; the leading shift value represents the number of leading zeros of the intermediate mantissa bit width; the mantissa overflow value represents the overflow value of the mantissa of the intermediate data represented by the target format.
[0218] In some embodiments, the method also includes: determining the number of leading 0s from the mantissa of the intermediate data through a leading determination module to obtain the leading shift value; performing a second shift processing on the mantissa of the intermediate data according to the leading shift value, the intermediate floating-point format and the target format through a second shift module to obtain a second shifted mantissa; the second shifted mantissa includes a truncated mantissa and a redundant mantissa; the truncated mantissa is located at the high bit of the second shifted mantissa, and the bit width is the same as the bit width of the intermediate mantissa; and performing a rounding operation on the truncated mantissa according to the redundant mantissa according to a mantissa rounding module in accordance with a first rounding method to obtain the intermediate restored mantissa and the mantissa overflow value.
[0219] In some embodiments, the method further includes: determining a round-up value according to the first rounding method through a rounding detection module and based on at least one of the numerical values of the truncated mantissa and the redundant mantissa; the round-up value is used to characterize the increase in the numerical value of the truncated mantissa; and summing the numerical value of the truncated mantissa and the round-up value through a mantissa addition module to obtain the intermediate restored mantissa and the mantissa overflow value.
[0220] In some embodiments, the method further includes: through the rounding detection module, when the value of the most significant two bits of the redundant mantissa is greater than a preset rounding threshold, determining the rounded-up value to be 1; or, when the value of the most significant two bits of the redundant mantissa is less than the preset rounding threshold, determining the rounded-up value to be 0; or, when the value of the most significant two bits of the redundant mantissa is equal to the preset threshold and the value of the truncated mantissa is an even number, determining the rounded-up value to be 0; or, when the value of the most significant two bits of the redundant mantissa is equal to the preset threshold and the value of the truncated mantissa is an odd number, determining the rounded-up value to be 1.
[0221] In some embodiments, the method further includes: through the rounding detection module, when the value of the preset high bit of the redundant mantissa is greater than or equal to the preset rounding threshold, determining the rounded-up value to be 1; or, when the value of the preset high bit of the redundant mantissa is less than the preset rounding threshold, determining the rounded-up value to be 0.
[0222] In some embodiments, the method also includes: determining the second shift value through the second shift module according to the leading shift value, the intermediate floating point format and the target format; when the second shift value is a positive value, the second shift processing is a left shift; when the second shift value is a negative value, the second shift processing is a right shift; performing the second shift processing on the mantissa of the intermediate data according to the second shift value to obtain the second shift mantissa of the original code; determining the second shift mantissa according to the positive and negative properties of the data to be converted and the second shift mantissa of the original code.
[0223] In some embodiments, the method further includes: through the second shift module, when the positive and negative properties of the data to be converted are positive numbers, using the second shift mantissa of the original code as the second shift mantissa; or, when the positive and negative properties of the data to be converted are negative numbers, using the complement of the second shift mantissa of the original code as the second shift mantissa.
[0224] In some embodiments, the target format is a floating point format; the method further comprises: obtaining the second shift value by the second shift module using the difference between the leading shift value, the intermediate mantissa bit width and the bit width of the target format data.
[0225] In some embodiments, the target format is an integer format; the method further comprises: obtaining the second shift value by the second shift module using the difference between the exponent of the intermediate data and the exponent offset of the intermediate floating point format, and the intermediate mantissa bit width.
[0226] In some embodiments, the method further includes: restoring the combined value of the intermediate restoration exponent and the intermediate restoration mantissa to floating-point format data according to the sign value of the intermediate data, the special judgment result and the target format through a floating-point restoration module; restoring the intermediate restoration mantissa to integer format data according to the sign value of the intermediate data, the special judgment result and the target format through an integer restoration module; determining the floating-point format data as the target format data through a target format selection module when the target format is a floating-point format; or determining the integer format data as the target format data when the target format is an integer format.
[0227] In some embodiments, the method further includes: when the special judgment result indicates that the data to be converted is a floating-point special number, determining, by the floating-point restoration module, a floating-point result value corresponding to the floating-point special number as the floating-point format data; or, when the special judgment result indicates that the data to be converted is not the special number and the target format is a first floating-point format, performing a first floating-point restoration process on a combined number of the intermediate restoration exponent and the intermediate restoration mantissa according to the sign value of the intermediate data to obtain the floating-point format data in the first floating-point format.
[0228] In some embodiments, the method further includes: through the integer restoration module, when the special judgment result indicates that the data to be converted is an integer special number, determining the integer result value corresponding to the integer special number as the target format data; or, when the special judgment result indicates that the data to be converted is not the special number and the target format is a first integer format, performing a first integer restoration process on the combined value of the intermediate restoration exponent and the intermediate restoration mantissa according to the sign value of the intermediate data to obtain the integer format data in the first integer format.
[0229] Fig.19 The structure of an electronic device provided by an embodiment of the present application is shown. Fig.19 As shown, the electronic device 170 includes a memory 1707, a processor 1708, and a computer program stored in the memory 1707 and executable on the processor 1708; wherein the processor 1708 is used to execute the data format conversion method in the aforementioned embodiment when running the computer program.
[0230] It is understood that the electronic device 170 also includes a bus system 1709; the various components in the electronic device 170 are coupled together through the bus system 1709. It is understood that the bus system 1709 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 1709 also includes a power bus, a control bus and a status signal bus.
[0231] It can be understood that the memory in the embodiments of the present application can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory (FlashMemory), a magnetic surface memory, an optical disk, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM), SyncLink Dynamic Random Access Memory (SLDRAM), and Direct Rambus Random Access Memory (DRRAM).The memories described in the embodiments of the present application are intended to include, but are not limited to, these and any other suitable types of memories.
[0232] The method disclosed in the above embodiment of the present application can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above processor may be a general-purpose processor, a DSP, or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present application, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in a memory, and the processor reads the signal in the memory and completes the steps of the above method in combination with its hardware.
[0233] An embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.
[0234] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as: multiple modules or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or modules can be electrical, mechanical or other forms.
[0235] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
Claims
1. A data format conversion device, characterized in that: include: A first conversion module, used for converting data to be converted in any one of a plurality of preset data formats into intermediate data in an intermediate floating point format; The intermediate exponent bit width of the intermediate floating point format is the maximum value of the bit widths of the multiple configuration exponents corresponding to the preset multiple formats; the intermediate mantissa bit width of the intermediate floating point format is the maximum value of the bit widths of the multiple configuration mantissas corresponding to the preset multiple data formats; the bit width of the configuration exponent of each data format is used to characterize the numerical range of the data format; the bit width of the configuration mantissa of each data format is used to characterize the data precision of the data format; The second conversion module is used to convert the intermediate data into the target format data according to a conversion method matching the target format data; the target format of the target format data is any one of the preset multiple data formats.
2. The device according to claim 1, characterized in that The device also includes: An acquisition module, used to acquire the bit width of the configuration exponent and the bit width of the configuration mantissa of each data format in the preset multiple data formats; The determination module is used to determine the maximum value among the bit widths of the configuration exponents of the multiple data formats as the intermediate exponent bit width, and to determine the maximum value among the configuration mantissa bit widths of the multiple data formats as the intermediate mantissa bit width.
3. The device according to claim 2, characterized in that The preset multiple data formats include floating point format; The acquisition module is further configured to use the bit width of the exponent bits of the floating-point format as the configured exponent bit width of the floating-point format; and determine the configured mantissa bit width of the floating-point format according to the mantissa bit width of the floating-point format and the floating-point integer bit width.
4. The device according to claim 2, characterized in that The preset multiple data formats include integer format; The acquisition module is further used to determine the intermediate bit width based on the total bit width of the integer format; determining a bit width of a configuration exponent in the integer format based on the intermediate bit width; And, the entire bit width of the integer format is used as the bit width of the configuration mantissa of the integer format.
5. The device according to any one of claims 1 to 4, characterized in that: The first conversion module comprises: A special judgment module, used for judging whether the data to be converted is a preset special number according to the to-be-converted format of the data to be converted and the target format, and obtaining a special judgment result; The exponent-mantissa conversion module is used to convert the data to be converted according to the intermediate floating point format, the format of the data to be converted and the special judgment result to obtain the intermediate data.
6. The device according to claim 5, characterized in that The exponent mantissa conversion module comprises: An exponent conversion module, configured to convert the exponent of the data to be converted according to the conversion offset difference between the intermediate floating point format and the format to be converted, and the special judgment result, to obtain the exponent of the intermediate data; The mantissa conversion module is used to convert the mantissa of the data to be converted according to the intermediate floating point format, the format of the data to be converted and the special judgment result to obtain the mantissa of the intermediate data.
7. The device according to claim 6, characterized in that The index conversion module comprises: A first index conversion module, used for obtaining the to-be-determined index of the intermediate data through the conversion offset difference and the to-be-converted data; The second index conversion module is used to determine the index of the intermediate data according to the special judgment result and the index to be determined.
8. The device according to claim 7, characterized in that The second exponent conversion module is further configured to, when the special judgment result indicates that the data to be converted is the preset special number, determine the preset special exponent value as the exponent of the intermediate data; or, when the special value judgment result indicates that the data to be converted is not the preset special number, determine the exponent to be determined as the exponent of the intermediate data; The preset special number includes an unformatted floating point number or an integer 0.
9. The device according to claim 6, characterized in that The mantissa conversion module comprises: A first mantissa conversion module, configured to perform a first shift process on the mantissa of the data to be converted according to the format to be converted and the intermediate floating-point format, to obtain a mantissa to be determined of the intermediate data; the bit width of the mantissa to be determined is the bit width of the intermediate mantissa; The second mantissa conversion module is used to determine the mantissa of the intermediate data according to the special judgment result and the mantissa to be determined.
10. The device according to claim 9, characterized in that: The first mantissa conversion module comprises: A mantissa extraction module, used for extracting the mantissa to be shifted from the data to be converted according to the format to be converted; the mantissa to be shifted is the original code data; The first shift module is used to perform a first shift process on the mantissa to be shifted according to the format to be converted, so as to obtain the mantissa to be determined.
11. The device according to claim 10, characterized in that The mantissa extraction module comprises: A positive processing module is used to perform absolute value processing on the mantissa of the data to be converted to obtain a positive mantissa; The mantissa selection module is used to determine the mantissa of the data to be converted as the mantissa to be shifted when the positive and negative properties indicate that the data to be converted is a positive number; or, when the positive and negative properties indicate that the data to be converted is a negative number, determine the positive mantissa as the mantissa to be shifted.
12. The device according to claim 10, characterized in that The format of the data to be converted is a floating point format; The first shift module is further used to concatenate the highest bit of the mantissa to be shifted with the integer bits of the floating-point format to obtain a floating-point decimal; and then use the floating-point decimal as the highest bit of the mantissa to be determined, and fill the remaining low bits with 0.
13. The device according to claim 12, characterized in that The format of the data to be converted is an integer format; The first shift module is further configured to use the to-be-shifted mantissa as the lowest bit of the to-be-determined mantissa, and fill the remaining high bits with 0.
14. The device according to claim 9, characterized in that The second mantissa conversion module is further configured to, when the special judgment result indicates that the data to be converted is the preset special number, determine the preset special mantissa value as the mantissa of the intermediate data; or, when the special judgment result indicates that the data to be converted is not the preset special number, determine the mantissa to be determined as the mantissa of the intermediate data; The preset special number includes an unformatted floating point number or an integer 0.
15. The device according to any one of claims 1 to 4, characterized in that: The second conversion module comprises: An exponential calculation module, used for adding the exponential impact value generated in the mantissa calculation process to the exponent of the intermediate data to obtain an intermediate restoration index; a mantissa calculation module, configured to perform a second shift process on the mantissa of the intermediate data according to the format of the data to be converted, the intermediate data, and the target format, to obtain an intermediate restored mantissa; the bit width of the intermediate restored mantissa is the same as the bit width of the mantissa of the target format; The restoration module is used to restore the mantissa value of the intermediate restoration exponent and the intermediate restoration mantissa according to the target format and the special judgment result to obtain the target format data.
16. The device according to claim 15, characterized in that The exponent impact value includes: a leading shift value and a mantissa overflow value; the leading shift value represents the number of leading zeros of the intermediate mantissa bit width; the mantissa overflow value represents the overflow value of the mantissa of the intermediate data represented by the target format.
17. The device according to claim 16, characterized in that The mantissa calculation module comprises: A leading determination module, used to determine the number of leading 0s from the mantissa of the intermediate data to obtain the leading shift value; A second shift module is used to perform a second shift process on the mantissa of the intermediate data according to the leading shift value, the intermediate floating point format and the target format to obtain a second shifted mantissa; the second shifted mantissa includes a truncated mantissa and a redundant mantissa; the truncated mantissa is located at a high position of the second shifted mantissa, and its bit width is the same as that of the intermediate mantissa; The mantissa rounding module is used to round the truncated mantissa according to the redundant mantissa in a first rounding mode to obtain the intermediate restored mantissa and the mantissa overflow value.
18. The device according to claim 17, characterized in that The mantissa rounding module comprises: a rounding detection module, configured to determine, according to the first rounding mode, a rounding-up value based on at least one of the value of the truncated mantissa and the value of the redundant mantissa; the rounding-up value is used to represent an increase in the value of the truncated mantissa; The mantissa addition module is used to sum the value of the truncated mantissa and the rounded-up value to obtain the intermediate restored mantissa and the mantissa overflow value.
19. The device according to claim 17, characterized in that The second shift module is further used to determine a second shift value according to the leading shift value, the intermediate floating point format and the target format; when the second shift value is a positive value, the second shift processing is a left shift; when the second shift value is a negative value, the second shift processing is a right shift; Perform the second shift processing on the mantissa of the intermediate data according to the second shift value to obtain a second shifted mantissa of the original code; The second shift mantissa is determined according to the positive and negative properties of the data to be converted and the second shift mantissa of the original code.
20. The device according to claim 19, characterized in that The second shift module is further used to use the second shift mantissa of the original code as the second shift mantissa when the positive and negative properties of the data to be converted are positive numbers; or, when the positive and negative properties of the data to be converted are negative numbers, use the complement of the second shift mantissa of the original code as the second shift mantissa.
21. The device according to claim 19, characterized in that The target format is a floating point format; The second shift module is further configured to obtain the second shift value by using a difference between the leading shift value, the intermediate mantissa bit width, and the bit width of the target format data.
22. The device according to claim 19, characterized in that The target format is an integer format; The second shift module is further used to obtain the second shift value by using the difference between the exponent of the intermediate data and the exponent offset of the intermediate floating point format, and the intermediate mantissa bit width.
23. The device according to claim 15, characterized in that The restoration module comprises: A floating point restoration module, used for restoring the combined value of the intermediate restoration exponent and the intermediate restoration mantissa into floating point format data according to the sign value of the intermediate data, the special determination result and the target format; An integer restoration module, used for restoring the intermediate restoration mantissa to integer format data according to the sign value of the intermediate data, the special judgment result and the target format; The target format selection module is used to determine the floating point format data as the target format data when the target format is a floating point format; or to determine the integer format data as the target format data when the target format is an integer format.
24. A data format conversion method, characterized in that: include: Converting data to be converted in any one of a plurality of preset data formats into intermediate data in an intermediate floating point format; The intermediate exponent bit width of the intermediate floating point format is the maximum value of the bit widths of the multiple configuration exponents corresponding to the preset multiple formats; the intermediate mantissa bit width of the intermediate floating point format is the maximum value of the bit widths of the multiple configuration mantissas corresponding to the preset multiple data formats; the bit width of the configuration exponent of each data format is used to characterize the numerical range of the data format; the bit width of the configuration mantissa of each data format is used to characterize the data precision of the data format; Converting the intermediate data into the target format data according to a conversion method matching the target format data; The target format of the target format data is any one of the preset multiple data formats.
25. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the data format conversion method as claimed in claim 24 when the computer program is running.
26. A computer storage medium, characterized in that Executable instructions are stored thereon, which are used to implement the data format conversion method as described in claim 24 when executed by a processor.
