CN118051200A - Data format conversion device and method, electronic device, and computer storage medium - Google Patents

Data format conversion device and method, electronic device, and computer storage medium Download PDF

Info

Publication number
CN118051200A
CN118051200A CN202410267651.0A CN202410267651A CN118051200A CN 118051200 A CN118051200 A CN 118051200A CN 202410267651 A CN202410267651 A CN 202410267651A CN 118051200 A CN118051200 A CN 118051200A
Authority
CN
China
Prior art keywords
data
mantissa
format
value
floating point
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410267651.0A
Other languages
Chinese (zh)
Inventor
请求不公布姓名
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Moore Threads Technology Co Ltd
Original Assignee
Moore Threads Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Moore Threads Technology Co Ltd filed Critical Moore Threads Technology Co Ltd
Priority to CN202410267651.0A priority Critical patent/CN118051200A/en
Publication of CN118051200A publication Critical patent/CN118051200A/en
Pending legal-status Critical Current

Links

Landscapes

  • Complex Calculations (AREA)

Abstract

The embodiment of the application discloses a data format conversion device and method, electronic equipment and a computer storage medium, wherein the device comprises the following components: the first conversion module is used for converting the data to be converted of any one of a plurality of preset data formats into intermediate data of an intermediate floating point format; the bit width of the middle exponent of the middle floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to a plurality of preset formats; the middle mantissa bit width of the middle floating point format is the maximum value of bit widths of a plurality of configuration mantissas corresponding to a plurality of preset data formats; the bit width of the configuration index for 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 accuracy of the data format; the second conversion module is used for converting the intermediate data into target format data according to a conversion mode matched with the target format data; the target format of the target format data is any one of a plurality of preset data formats.

Description

Data format conversion device and method, electronic device, and computer storage medium
Technical Field
The present application relates to the field of circuit technologies, and in particular, to a data format conversion device and method, an electronic device, and a computer storage medium.
Background
Currently, in the case of integer and floating point numbers in multiple formats, a specific hardware circuit may be generally adopted to convert one format determined in the multiple formats into another determined format, or a larger bit width is configured on the hardware circuit to realize format conversion between the determined formats; thus, the data format convertible by the data format conversion circuit realized by the hardware circuit is limited, and the consumption of hardware resources is large, so that the function of the data format conversion hardware circuit is poor.
Disclosure of Invention
The embodiment of the application provides a data format conversion device and method, electronic equipment and a computer storage medium, which can reduce the consumption of hardware resources and increase the format diversity supported by data conversion, thereby improving the function of a data format conversion hardware circuit.
The technical scheme of the application is realized as follows:
The embodiment of the application provides a data format conversion device, which comprises:
The first conversion module is used for converting the data to be converted of any one of a plurality of preset data formats into intermediate data of an intermediate floating point format; the bit width of the middle exponent of the middle floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to the preset various formats; the middle mantissa bit width of the middle floating point format is the maximum value of bit widths of a plurality of configuration mantissas corresponding to the preset various data formats; the bit width of the configuration index 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 accuracy of the data format;
the second conversion module is used for converting the intermediate data into the target format data according to a conversion mode matched with the target format data; the target format of the target format data is any one of the preset multiple data formats.
The embodiment of the application provides a data format conversion method, which comprises the following steps:
converting data to be converted of any one of a plurality of preset data formats into intermediate data of an intermediate floating point format through a first conversion module; the bit width of the middle exponent of the middle floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to the preset various formats; the middle mantissa bit width of the middle floating point format is the maximum value of bit widths of a plurality of configuration mantissas corresponding to the preset various data formats; the bit width of the configuration index 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 accuracy of the data format;
Converting the intermediate data into the target format data by a second conversion module according to a conversion mode matched with the target format data; the target format of the target format data is any one of the preset multiple data formats.
The embodiment of the application provides electronic equipment, which comprises:
A memory for storing a computer program;
and the processor is used for executing the data format conversion method when the computer program runs.
The embodiment of the application provides a computer readable storage medium, which is stored with executable instructions for realizing the data format conversion method when being executed by a processor.
The embodiment of the application provides a data format conversion device and method, electronic equipment and a computer storage medium, wherein the data format conversion device firstly converts data to be converted into intermediate data in an intermediate floating point format, then converts the intermediate data into target format data, and the intermediate tail digital width of the intermediate floating point format is the maximum value of the bit width of a plurality of configuration indexes corresponding to a preset plurality of formats, and the intermediate tail digital width is the maximum value of the bit width of a plurality of configuration tails corresponding to the preset plurality of formats; that is, the range of values of the intermediate floating point format is the minimum value that can satisfy the range of data of the preset plurality of formats, and the precision of data of the intermediate floating point format is the minimum value that can satisfy the precision of data of the preset plurality of formats. Therefore, the data format conversion device can realize the mutual conversion among preset various data formats by setting the intermediate floating point format, and the diversity of data conversion is improved.
Drawings
Fig. 1 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application;
fig. 2 is a schematic diagram of a data format conversion device according to an embodiment of the present application;
Fig. 3 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application;
Fig. 5 is a schematic diagram of a data format conversion device according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application;
FIG. 9 is a schematic diagram I of a first shift process according to an embodiment of the present application;
FIG. 10 is a second schematic diagram of a first shift process according to an embodiment of the present application;
FIG. 11 is a third schematic diagram of a first shift process according to an embodiment of the present application;
Fig. 12 is a schematic diagram of a data format conversion device according to an embodiment of the present application;
fig. 13 is a schematic structural diagram of a data format conversion device according to an embodiment of the present application;
Fig. 14 is a schematic diagram eleven of a structure of a data format conversion device according to an embodiment of the present application;
Fig. 15 is a schematic diagram showing a data format conversion device according to an embodiment of the present application;
Fig. 16 is a schematic diagram of a color value determining apparatus according to an embodiment of the present application;
Fig. 17 is a schematic diagram fourteen of a data format conversion device according to an embodiment of the present application;
Fig. 18 is a flowchart of a data format conversion method according to an embodiment of the present application;
Fig. 19 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present application.
Detailed Description
The present application will be further described in detail with reference to the accompanying drawings, for the purpose of making the objects, technical solutions and advantages of the present application more apparent, and the described embodiments should not be construed as limiting the present application, and all other embodiments obtained by those skilled in the art without making any inventive effort are within the scope of the present application.
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is to be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments and can be combined with one another without conflict.
In the following description, the terms "first", "second", "third" and the like are merely used to distinguish similar objects and do not represent a specific ordering of the objects, it being understood that the "first", "second", "third" may be interchanged with a specific order or sequence, as permitted, to enable embodiments of the application described herein to be practiced otherwise than as illustrated or described herein.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the application only and is not intended to be limiting of the application.
In order to facilitate understanding of the present solution, before explaining the embodiments of the present application, an application background in the embodiments of the present application is explained.
With the development of computer technology, a graphics processor (Graph Processing Unit, GPU) is generally required for data computation by a computer, so that the dependence of a graphics card on a central processing unit (Central Processing Unit, CPU) is reduced. Because of the different data formats stored between the GPU and the CPU, or between the GPU and the graphics card, the GPU often needs to convert between data in different formats, including floating point numbers in various formats and integers in various formats. For example, the graphics card may store data in the form of 32-bit floating point numbers, the GPU may store data in the form of additional 16-bit floating point numbers, etc. Where converting data in one defined format to data in another defined format typically requires a specific circuit to implement. Illustratively, once implemented into a particular hardware circuit, the hardware circuit typically only performs the conversion of floating point numbers in a certain format to integers in a certain format, given the theoretical approach of converting any floating point number to any integer. That is, the data conversion format achievable by one hardware circuit is quite single. In order to implement conversion between multiple determined formats, a hardware circuit needs to set a larger bit width, resulting in redundant bit width and wasting hardware resources.
In order to solve the above-mentioned problems, an embodiment of the present application provides a data format conversion device, which can convert data in a preset plurality of formats through a hardware circuit under the condition of presetting a plurality of format determinations. The device can be applied to any equipment which needs to be converted in preset multiple formats. In some embodiments, the apparatus may be provided in a device that requires data computation by a graphics processor (Graph Processing Unit, GPU), thus enabling an increase in the variety of data formats supported by the device. These devices may be servers, notebook computers, tablet computers, desktop computers, smart televisions, set-top boxes, mobile devices (e.g., mobile phones, portable video players, personal digital assistants, dedicated messaging devices, portable gaming devices), etc.
Fig. 1 is a schematic structural diagram of an alternative data format conversion device according to an embodiment of the present application. As shown in fig. 1, the apparatus may include: the first conversion module 10 is configured to convert data to be converted, which is preset in any one of a plurality of data formats, into intermediate data in an intermediate floating point format; the bit width of the middle exponent of the middle floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to a plurality of preset formats; the middle mantissa bit width of the middle floating point format is the maximum value of bit widths of a plurality of configuration mantissas corresponding to a plurality of preset data formats; the bit width of the configuration index for 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 accuracy of the data format; a second conversion module 20, configured to convert the intermediate data into target format data according to a conversion manner matched with the target format data; the target format of the target format data is any one of a plurality of preset data formats.
In the embodiment of the application, the data format conversion device can realize format conversion in the preset multiple data formats. The preset plurality of data formats can comprise a plurality of floating point formats and a plurality of integer formats; here, the preset various data formats may be set as required, and the embodiment of the present application is not limited.
In the embodiment of the present application, the data format conversion device may convert the input data to be converted into the intermediate floating point format through the first conversion module 10, and then convert the intermediate floating point format into the target format in the preset multiple data formats through the second conversion module 20.
In an embodiment of the application, the intermediate floating point format includes sign bits, exponent bits, and mantissa bits; wherein the bit width of the index bit is the middle index bit width, the bit width of the mantissa bit is the middle mantissa bit width, and the bit width of the sign bit is 1. In the case of intermediate exponent bitwidth and intermediate exponent bitwidth determination, the intermediate floating point format is determined.
In the embodiment of the present application, the bit width of the configuration index of each format is used to represent the numerical range of the format, that is, the data range that the bit width of the configuration index of each format can represent should be greater than or equal to the data range of the format itself. The bit width of the configuration mantissa for each format is used to represent the numerical precision of the format, that is, the bit width of the configuration mantissa for 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.
It should be noted that, for any integer format, the bit width int_pw of the configuration index can completely cover the numerical range that can be represented by itself when satisfying the formula (1) and the formula (2).
2 int_pw -1-Bias ≡int_w-1 formula (1)
Bias=2 (int_pw-1) -1 formula (2)
For example, if the bit width of the integer is 32, it is determined that the bit width int_pw of the configuration index thereof may be 6 at minimum according to the formula (1) and the formula (2). If the bit width of the integer is 16, it can be determined that the bit width of the configuration index can be 5 at the minimum.
In the embodiment of the application, the bit width of the configuration index 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 bit width of the middle index can be the maximum value of the bit widths of the preset multiple configuration indexes corresponding to the multiple data formats; thus, the data range which can be represented by the middle digital width can be larger than or equal to the maximum data range of a plurality of preset data formats; the intermediate mantissa bit width may be a maximum value of bit widths of a plurality of configuration mantissas corresponding to a plurality of preset data formats. Here, the middle exponent bit width and the middle mantissa bit width of the middle floating point format may be determined according to a preset variety of data formats, which is not limited in the embodiment of the present application.
It should be noted that, the data precision that can be represented by the middle tail digital width may be greater than or equal to the maximum data precision of preset multiple data formats; that is, the intermediate floating point format may accurately represent data of each of the preset plurality of data formats. In some embodiments, the data precision that can be represented by the middle tail digital width is equal to a maximum data precision of a preset plurality of data formats; at this time, the number of bits in the intermediate floating point format is minimum, so that hardware resources are saved to the greatest extent, and meanwhile, the data precision is ensured. In the 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 second conversion module 20 may convert the intermediate data in the intermediate floating point format into the target format data according to the target format of the target format data in a conversion manner of converting the intermediate floating point format into the target format.
In some embodiments of the present application, the target format is a floating point format, and the second conversion module 20 may convert the intermediate floating point format into any one of a predetermined plurality of data formats.
In some embodiments of the present application, the target format is an integer format, and the second conversion module 20 may convert the intermediate floating point format into any one of a predetermined plurality of data formats. In the process of converting the intermediate floating point format into the integer format, the integer format may be directly rounded, or rounded according to the decimal integer, the rounding mode may be rounding, or nearest-neighbor even Rounding (RNE), which may be set according to needs, and the embodiment of the present application is not limited.
It can be understood that, because the data format conversion device firstly converts the data to be converted into intermediate data in the intermediate floating point format, and then converts the intermediate data into data in the target format, the intermediate mantissa bit width of the intermediate floating point format is a maximum value of bit widths of a plurality of configuration indexes corresponding to the preset multiple formats, and the intermediate mantissa bit width is a maximum value of bit widths of a plurality of configuration mantissas corresponding to the preset multiple formats; that is, the range of values of the intermediate floating point format is the minimum value that can satisfy the range of data of the preset plurality of formats, and the precision of data of the intermediate floating point format is the minimum value that can satisfy the precision of data of the preset plurality of formats. Therefore, the data format conversion device can realize the mutual conversion among preset various data formats by setting the intermediate floating point format, and the diversity of data conversion is improved.
Based on fig. 1, fig. 2 shows a schematic structure of an alternative data conversion device. As shown in fig. 2, the data format conversion apparatus 10 may further include an acquisition module 30 and a determination module 40; the acquiring module 30 is configured to acquire a bit width of a configuration exponent and a bit width of a configuration mantissa of each of a plurality of preset data formats; a determining module 40, configured to determine a maximum value of the configuration exponent bitwidths of the plurality of data formats as the middle exponent bitwidth, and determine a maximum value of the configuration mantissa bitwidths of the plurality of data formats as the middle mantissa bitwidth.
In the embodiment of the present application, the data format conversion device may acquire the bit width of the configuration index and the bit width of the configuration mantissa of each of the preset multiple formats through the acquisition module 30, and then determine the maximum value from the acquired bit widths of the configuration indexes of all the formats as the intermediate mantissa bit width through the determination module 40, and determine the maximum value from the acquired bit widths of the configuration mantissas of all the formats as the intermediate mantissa bit width.
In the embodiment of the application, the maximum value in the bit width of the configuration index of all formats represents the maximum numerical range which can be represented by all formats, and the maximum value in the bit width of the configuration mantissa of all formats represents the maximum data precision which can be represented by all formats.
It will be appreciated that the data format conversion means may determine the intermediate exponent and intermediate mantissa bit widths of the intermediate floating point format based on a predetermined maximum range of values and a predetermined maximum data precision that may be represented by the plurality of data formats. Therefore, the setting flexibility of presetting various data formats can be improved, and the data format conversion device can be realized by adopting the minimum middle digit width and the minimum middle tail digit width, so that the consumption of hardware resources is reduced.
In the embodiment of the present application, the obtaining module 30 may determine the bit width of the configuration exponent and the bit width of the configuration mantissa according to each of a preset plurality of data formats.
In some embodiments of the present application, the preset plurality of data formats include a floating point format, the obtaining module 30 is further configured to use a bit width of exponent bits in the floating point format as a configuration exponent bit width in the floating point format; and determining the configuration 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.
In an embodiment of the present application, the floating point format includes exponent bits and mantissa bits. The fetch module 30 may directly take the bit width of the exponent bits in floating point format as the bit width of its configuration exponent. Because the mantissa bits of the floating point format are only decimal places, the whole digits are not embodied in the floating point format, and the obtaining module 30 needs to increase the whole digits of the floating point based on the digits of the mantissa bits to obtain the digits of the configured mantissa; the floating point integer bit width is the bit width of the integer bits in floating point format. In some embodiments, the integer digits of the floating point format are 1 and the floating point integer digits are 1 wide.
It can be appreciated 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, and extract the bit width of the mantissa bits plus 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 of the floating point format can be increased.
In some embodiments of the present application, the preset plurality of data formats includes an integer format, and the obtaining module 30 is further configured to determine an intermediate bit width based on all bit widths of the integer format; determining a bit width of the configuration index in integer format based on the intermediate bit widths; and taking the whole bit width of the integer format as the bit width of the configuration mantissa of the integer format.
In the embodiment of the present application, the integer format includes a signed integer format and an unsigned integer format, and for any one integer format, the obtaining module 30 may use the bit widths of all bits in the integer format as the configuration mantissa bit width; taking the logarithm with 2 as the base, and rounding the logarithm upwards to obtain the intermediate bit width. The full bit width of an integer is represented by a power of 2 by a base 2 logarithm, and therefore, a bit width of a logarithm plus 1 as a configuration index can characterize the numerical range of a binary integer. Here, the logarithm based on 2 may not be an integer for any full bit width, and it is necessary to round the logarithm upward so that the numerical range in the integer format is within the numerical range indicated by the bit width of the configuration index.
In the embodiment of the present application, for any integer format, the bit width int_pw of its configuration index can be determined by equation (3).
Where int_w is the bit width of an integer.
It can be understood that the data format conversion device may extract the whole bit width of the integer format, take the whole bit width as the bit width of the configuration mantissa, and calculate the whole bit width according to the formula (3) to obtain the bit width of the configuration exponent, so that the efficiency of determining the bit width of the configuration exponent and the bit width of the configuration mantissa of the integer format can be increased.
Illustratively, the preset plurality of data formats include FP32 and UNIT32. The exponent bit width of FP32 is 8, and the configuration exponent bit width is 8; the mantissa bit width of FP32 is 23 and the configuration mantissa bit width is 24. The UNIT32 is an integer, the full bit width is 32, the configuration mantissa bit width is 32, and the configuration exponent bit width is 6. Therefore, the intermediate exponent bit width of the intermediate floating point format is 8 and the intermediate mantissa bit width is 32 for the predetermined plurality of data formats.
Based on fig. 1, fig. 3 shows the structure of an alternative data conversion device. As shown in fig. 3, the first conversion module 10 may include: a special judgment module 101 and an exponent mantissa conversion module 10-2. The special judging module 101 is configured to judge whether the data to be converted is a preset special number according to the format to be converted and the target format of the data to be converted, so as to obtain a special judging result; and the exponent mantissa conversion module 10-2 is used for converting 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 intermediate data.
In the embodiment of the application, different formats to be converted and combinations of target formats can be combined, and preset special numbers can be the same or different; in this regard, it may be set as needed, and the embodiment of the present application is not limited. The preset special number includes a floating point special number and an integer special number. Under the condition that the format to be converted is a floating point format, presetting a special number as a floating point special number; in the case that the format to be converted is an integer format, the preset special number is an integer special number.
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 outlier (denormal number), the Infinity (INF), the non-numeric value (NAN), the absolute value being less than the minimum absolute value representable by the target format and the absolute value being greater than the maximum absolute value representable by the target format.
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, the second floating point special number comprises at least one of: a non-numeric value, a positive infinity (+inf), a maximum value that is greater than the target format can represent, a negative infinity (-INF), and a minimum value that is less than the target format can represent.
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: 0. greater than the maximum positive number representable by the target format and less than the minimum negative number representable by the target format.
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, the second integer special number comprises at least one of: greater than the maximum representable by the target format and less than the minimum representable by the target format.
In the embodiment of the application, the offset bias corresponding to different floating point formats is different, and the offset of the integer format is 0. Therefore, in the case of converting various data formats into an intermediate floating point format, the data format converting apparatus needs 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.
In the embodiment of the present application, after the data format conversion device obtains the special judgment result through the special judgment module 101, the preset special number can be directly used as the intermediate data when the special judgment result represents that the data to be converted is the preset special number, thereby improving the conversion efficiency.
Based on fig. 3, fig. 4 shows the structure of an alternative data conversion device. As shown in fig. 4, the exponent mantissa conversion module 10-2 includes: the exponent converting module 102 is 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 an exponent of the intermediate data; and the mantissa conversion module 103 is configured to perform conversion processing on 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, so as to obtain the mantissa of the intermediate data.
In the embodiment of the present application, the exponent converting module 102 may perform conversion processing on the exponent of the data to be converted, and the mantissa converting module 103 may perform conversion processing on the mantissa of the data to be converted, so that the conversion processing on the exponent and the mantissa of the data to be converted may be performed simultaneously by different modules, which may improve the conversion efficiency of the data to be converted.
Based on fig. 4, fig. 5 shows the structure of an alternative data conversion device. As shown in fig. 5, the exponential conversion module 102 may include: a first exponential conversion module 1021 and a second exponential conversion module 1022. The first exponent converting module 1021 is configured to obtain an exponent to be determined of the intermediate data by converting the offset difference value and the data to be converted; the second exponent converting module 1022 is configured to determine an exponent of the intermediate data according to the special determination result and the exponent to be determined.
In the embodiment of the present application, the exponent conversion module 102 may first add the conversion offset difference mbias and the exponent sexp of the data to be converted by the first exponent conversion module 1021 to obtain the exponent text to be determined of the intermediate data, see formula (4), and the conversion offset difference mbias is see formula (5); and then, the second index module 1022 combines the special judgment result to select one index from the indexes to be determined of the intermediate data and the preset special index value corresponding to the preset special number as the index of the intermediate data.
Textp= mbias + sexp formula (4)
Mbias = tbias-sbias formula (5)
Wherein tbias denotes an exponent offset of the intermediate floating point format, sbias denotes an exponent offset of the format to be converted.
It may be appreciated that the data conversion device may obtain the special judgment result through the special judgment module 101 while determining, by the first index conversion module 1021, the index to be determined of the intermediate data as the index of the candidate intermediate data, so that the second index conversion module 1022 may quickly determine the index of the intermediate data from the index to be determined of the intermediate data and the preset special index value, thereby improving the efficiency of determining the index of the intermediate data.
In some embodiments of the present application, the second exponent converting module 1022 is further configured to determine a preset special exponent value as an exponent of the intermediate data if the special determination result indicates that the data to be converted is a preset special number; or under the condition that the special judgment result represents that the data to be converted is not a preset special number, determining the index to be determined as the index of the intermediate data; the preset special number includes an unformatted floating point number or an integer 0.
It should be noted that the preset special number and the preset special index value corresponding to the preset special number may be set according to the need. In an embodiment of the present application, the preset special number includes an unformatted floating point number and an integer 0. Under the condition that the configuration index of the data to be converted is 0, determining that the data to be converted is a non-formatted floating point number; under the condition that the format to be converted is an integer and all bits of the data to be converted are 0, determining that the data to be converted is an integer 0, and presetting a special index value to be 0.
It may be appreciated that the second exponent conversion module 1022 may obtain a special determination result, and in the case where the special determination result characterizes that the data to be converted is a non-formatted floating point number or an integer 0, may directly determine 0 as the exponent to be determined of the intermediate data; without having to determine the index to be determined of the intermediate data by taking the transition offset difference. In this way, the efficiency of determining the index of the intermediate data can be improved.
In some embodiments, the second exponent converting module 1022 may be implemented as a selector for determining the exponent of the intermediate data from the preset special value and the exponent to be determined of the intermediate data according to the special determination result.
Based on fig. 5, fig. 6 shows a schematic structural diagram of an alternative data conversion device. As shown in fig. 6, the first exponential conversion module 1021 may include: a conversion offset difference value acquisition module 10211, an exponent extraction module 10212, and an exponent addition module 10213. The conversion offset difference value obtaining module 10211 is configured to obtain a conversion offset difference value; an index extraction module 10212 for extracting an index of the data to be converted; the exponent adding module 10213 is configured to add the exponent of the data to be converted and the conversion offset difference value to obtain the exponent to be determined of the intermediate data.
In the embodiment of the present application, the first exponential conversion module 1021 may obtain the conversion offset difference value through the conversion offset difference value obtaining module 10211, and extract the exponent of the data to be converted through the exponent extracting module 10212; in this way, the efficiency of the exponent addition module 10213 to acquire the conversion offset difference and the exponent of the data to be converted can be improved, thereby improving the determination efficiency of the exponent to be determined of the intermediate data.
In some embodiments, the exponent addition module 10213 may be implemented as an adder; the two inputs of the adder are respectively an index of data to be converted and a conversion offset difference value, and the two inputs are output as an index to be determined of intermediate data. The number of bits of the adder may be set according to actual needs, and the embodiment of the application is not limited.
In some embodiments of the present application, the conversion offset difference value obtaining module 10211 is further configured to determine, from the preset offset difference values, an offset difference value that matches the format of the data to be converted, as the conversion offset difference value; the preset offset includes a difference between an exponent offset of each of the preset plurality of data formats and an exponent offset of the intermediate floating point format.
In the embodiment of the present application, the data conversion device may preset an offset difference between a plurality of preset data formats and an intermediate floating point format, that is, a preset offset difference. Thus, the data conversion device can select the offset difference value matched with the format to be converted from the preset offset difference value as the conversion offset difference value.
Illustratively, presetting the plurality of data formats includes: format 1, format 2, and format 3, the preset offset difference values include mbias1, mbias2, and mbias3; mbias1 denotes a conversion offset difference value of format 1 and the intermediate floating point format, mbias denotes a conversion offset difference value of format 2 and the intermediate floating point format, and Mbias denotes a conversion offset difference value of format 3 and the intermediate floating point format. If the format to be converted is format 1, the conversion offset difference is mbias1.
It can be appreciated that, since the data conversion device stores the preset offset difference value, the data conversion device can quickly select one of the preset offset difference values as the conversion offset difference value, thereby improving the determination efficiency of the offset conversion difference value.
In some embodiments of the application, the conversion offset difference value acquisition module 10211 may include: the offset acquisition module and the offset difference determination module. The offset acquisition module is used for acquiring the index offset of the intermediate floating point format and the index offset of the format of the data to be converted; and the offset difference determining module is used for taking 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 a conversion offset difference.
In the embodiment of the present application, the data format conversion device may 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 obtaining module, and then subtract the exponent offset sbias of the format of the data to be converted from the exponent offset tbias of the intermediate floating point format according to formula (5) through the offset difference determining module to obtain the converted offset difference mbias.
It can be understood that, even if the preset plurality of data formats change, the data format conversion device can determine the intermediate floating point format, so that the conversion offset difference value can be determined through the offset acquisition module and the offset difference value determination module, thereby increasing the flexibility of the data format conversion device for converting data.
In some embodiments of the present application, the offset obtaining module is further configured to determine an exponent offset of the intermediate floating point format according to the intermediate exponent bit width of the intermediate floating point format; and determining the index offset of the format to be converted according to the configuration index bit width of the format to be converted.
In the embodiment of the present application, since different exponent bitwidths correspond to different exponent offsets, the offset obtaining module may determine the exponent offset according to the data format, see formula (6).
Bias=2 k-1 -1 formula (6)
Where k represents the configuration index bit width of the data format.
The offset acquisition module may determine the exponent offset tbias for the intermediate floating point format based on the intermediate exponent bit width for the intermediate floating point format. The intermediate exponent bit width and the configuration exponent bit width of the intermediate floating point format are the same, and are the exponent bit widths of the intermediate floating point format. Illustratively, the intermediate floating point format is FP32 with a configuration exponent bit width of 8 and an exponent offset tbias of 127; the intermediate floating point format is FP16, the exponent bit width is 5, and the exponent offset tbias is 15.
The offset obtaining module may determine an index offset tbias of the format to be converted according to the configuration index bit width of the format to be converted. For example, the format to be converted is UNIT16, the configuration index bit width is 5, and the index offset tbias is 15.
It can be appreciated that the data format conversion device can quickly determine the index offset corresponding to the data format according to the data format and the formula (6), thereby improving the efficiency of converting the offset difference value.
Based on fig. 6, fig. 7 shows the structure of an alternative data conversion device. As shown in fig. 7, 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 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 middle mantissa bit width; and the second mantissa conversion module 1032 is configured to determine an intermediate data mantissa according to the special determination result and the mantissa to be determined.
In the embodiment of the present application, since the mantissa bit width of the format to be converted may be different from the intermediate mantissa bit width, the data conversion device may perform the 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 intermediate mantissa bit width; and determining whether the mantissa to be determined of the intermediate data is intermediate mantissa data according to the special judgment result through the second mantissa conversion module 1032.
In the embodiment of the application, since only decimal places in mantissa bits of the data to be converted in the floating point format are represented in the mantissa bits of the data to be converted, in order to keep the numerical value of the data to be converted in the floating point format unchanged, the first shift processing needs to be performed on the integer 1 and the mantissa bits in the floating point format together, so that the first shift processing mode when the data to be converted is in the floating point format is different from the first shift processing mode when the data to be converted is in the integer.
It can be understood that the data conversion device can perform the first shift processing in different ways according to whether the data to be converted is in a floating point format or an integer format, and the mantissa accuracy of the intermediate data can be improved.
In some embodiments of the present application, the second mantissa conversion module 1032 is further configured to determine a preset special mantissa value as the mantissa of the intermediate data if the special determination result indicates that the data to be converted is a preset special number; or under the condition that the special judgment result represents that the data to be converted is not the preset special number, determining the mantissa to be determined of the intermediate data as the mantissa of the intermediate data; the preset special number includes an unformatted floating point number or an integer 0.
It should be noted that, the preset special number and the preset special mantissa value corresponding to the preset special number may be set as required. In an embodiment of the present application, the preset special number includes an unformatted floating point number and an integer 0. Under the condition that the configuration index of the data to be converted is 0, determining that the data to be converted is a non-formatted floating point number; under the condition that the format to be converted is an integer and all bits of the data to be converted are 0, determining that the data to be converted is an integer 0, and presetting a special mantissa value as 0.
It may be appreciated that the second mantissa conversion module 1032 may obtain a special determination result, and in a case where the special determination result characterizes that the data to be converted is a non-formatted floating point number or an integer 0, may directly determine 0 as the mantissa to be determined of the intermediate data; without having to determine the mantissa to be determined of the intermediate data by the first shift process. In this way, the efficiency of determining the mantissa of the intermediate data can be improved.
Based on fig. 7, fig. 8 shows the structure of an alternative data conversion device. As shown in fig. 8, 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 configured to extract a 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 configured 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.
In the embodiment of the present application, the mantissa extracted from the data to be converted by the mantissa extraction module 10311 may be the complement code or the original code, but during the first shift processing, the data conversion device needs to process the original code, so the data conversion device needs to determine whether the mantissa of the data to be converted is the complement code, and 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.
In the embodiment of the present application, after obtaining the mantissa to be shifted, the data conversion device may 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 shifting module 10312 may be implemented as a shifter, where an input of the shifter is a mantissa to be shifted, and the shifter is configured to perform a first shifting process on the mantissa to be shifted, and output a mantissa to be determined of the intermediate data.
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 further configured to splice the upper bits of the mantissas to be shifted into integer digits in the floating point format to obtain floating point decimal places; and taking the floating point decimal as the highest order of the mantissa to be determined, and supplementing 0 to the rest low order.
In the embodiment of the present application, the format of the data to be converted is a floating point format, and the first shift module 10312 needs to splice the integer bit 1 of the floating point format with the highest bit of the mantissa to be shifted to obtain the decimal of the floating point format, that is, the decimal of the floating point; the floating point fraction is then taken as the most significant bit of the mantissa to be determined of the intermediate data, with the remaining slots being filled by 0, see FIG. 9. After the first shift process, integer bit 1 of the floating point format will be at the highest bit of the mantissa of the intermediate data to be determined.
It can be appreciated that, by performing the first shift processing on the data to be converted in the floating point format, the mantissa of the intermediate data represented by the mantissa to be determined can be the same as the numerical value represented by the mantissa of the data to be converted, so that the accuracy of converting the floating point format into the mantissa of the intermediate data in the intermediate floating point format can be improved.
In some embodiments of the application, the format of the data to be converted is an integer format; the first shift module 10312 is further configured to take the mantissa to be shifted as a lowest order bit of the mantissa to be determined, and complement the remaining high order bits by 0.
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 may itself represent the value of the mantissa, so the first shift module 10312 may directly use the mantissa of the data to be converted as the lowest order bit of the mantissa to be determined of the intermediate data, and the remaining high order bits are complemented with 0, see fig. 9. After the first shift process, the value of the mantissa to be determined of the intermediate data is the same as the value of the integer format.
It can be appreciated that, by the first shift processing of the data to be converted in integer format, the mantissa of the intermediate data represented by the mantissa to be determined can be the same as the numerical value represented by the mantissa of the data to be converted, and the accuracy of the mantissa of the intermediate data converted in integer format into intermediate floating point format can be improved.
Illustratively, the predetermined plurality of data formats include FP32 and SINT32 with a middle tail bit width of 32. The first shift module 10312 performs a first shift processing on the mantissa of the FP32, as shown in fig. 10, where the mantissa to be shifted includes a combination of 23 bits of the mantissa of the FP32 and integer 1, and a total of 24 bits; the high order 24 bits of the mantissa to be determined of the intermediate data are mantissas to be shifted, and the rest 8 bits are complemented with 0. The first shift module 10312 performs a first shift on the mantissa of the SINT32 as shown in fig. 11, where the low order of the mantissa to be determined of the intermediate data is the 31-bit mantissa of the SINT32, and the most significant 1-bit is complemented by 0.
It can be understood that the data conversion device can acquire the mantissa to be shifted of the original code through the mantissa extraction module, and then perform first shifting processing on the mantissa to be shifted; in this way, the accuracy of the mantissa of the intermediate data can be improved.
Based on fig. 8, fig. 12 shows the structure of an alternative data conversion device. As shown in fig. 12, the mantissa extraction module 10311 may include: a fetch positive processing module 10311-1 and an extract mantissa selection module 10311-2. The positive processing module 10311-1 is configured to perform absolute value processing on mantissas of data to be converted to obtain positive mantissas; an extraction mantissa selection module 10311-2, configured to determine, in a case where positive and negative properties characterize the data to be converted as positive numbers, the mantissa of the data to be converted as a mantissa to be shifted; or determining the positive mantissa as the mantissa to be shifted if the positive and negative properties characterize the data to be converted as negative.
In the embodiment of the present application, the mantissa extraction module 10311 may obtain the positive mantissa by performing absolute value processing on the mantissa of the data to be converted by the positive processing module 10311-1. The data to be converted is negative, the mantissa of the data to be converted is complementary, and the positive mantissa is the original; the data to be converted is positive, and the mantissa of the data to be converted is unchanged and is the original value.
In an embodiment of the present application, the mantissa extraction module 10311 may select one from the positive mantissa and the mantissa of the data to be converted as the mantissa to be shifted by the extraction mantissa selection module 10311-2 according to the positive and negative properties of the data to be converted. Under the condition that the data to be converted is negative, selecting positive mantissa as mantissa to be shifted; and selecting the mantissa of the data to be converted as the mantissa to be shifted under the condition that the data to be converted is positive.
It will be appreciated that by taking the positive processing module 10311-1 and the mantissa selection module 10311-2, the mantissa extraction module 10311 may output a uniquely determined mantissa to be shifted based on the positive and negative properties of the data to be converted.
Based on fig. 12, fig. 13 shows a structure of an alternative data conversion device. As shown in fig. 13, the second conversion module 20 includes: an exponent calculation module 201, a mantissa calculation module 202, and a reduction module 203. The exponent calculating module 201 is configured to add an exponent influence value generated in the mantissa calculating process to an exponent of the intermediate data to obtain an intermediate reduction exponent; the mantissa calculation module 202 is 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 reduction mantissa is the same as the mantissa bit width of the target format; and the reduction module 203 is configured to perform reduction processing on the mantissa value combined by the intermediate reduction exponent and the intermediate reduction mantissa according to the target format and the special judgment result, so as to obtain target format data.
In the embodiment of the application, the target format is an integer format, and the mantissa bit width of the target format is the bit width of other bits except the sign bit of the integer format. 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.
In the embodiment of the present application, the mantissa calculation module 202 performs the second shift processing on the mantissa of the intermediate data, and may determine a numerical value that may be represented by the mantissa of the intermediate data 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 is affected; for example, the second shift processing is to shift the mantissa of the intermediate data left, which results in an exponent decrease of the intermediate data, and the second shift processing is to shift the mantissa of the intermediate data right, which results in an exponent increase of the intermediate data. Or when the second shift process needs to intercept the mantissa bit wide units of the target format from the mantissa of the intermediate data, the rounding process may generate mantissa overflow, which may also result in an exponent increase of the intermediate data. Therefore, when the mantissa calculation module 202 performs the second shift processing on the mantissa of the intermediate data, the exponent influence value may be determined according to the change of the mantissa digit, and the exponent influence value may be positive or negative. In this manner, the exponent calculation module 201 may add the exponent influence value to the exponent of the intermediate data to obtain an intermediate reduction exponent.
In the embodiment of the present application, the restoration module 203 may determine the numerical value of the data to be converted through 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, when the special determination result of the data to be converted indicates that the data to be converted is a special number, the special number may be corresponding to
It may be appreciated that the second conversion module 20 may calculate the exponent of the intermediate data and the mantissa of the intermediate data by the exponent calculation module 201 and the mantissa calculation module 202, respectively, so as to improve the calculation efficiency of the intermediate reduction exponent and the intermediate reduction mantissa.
In some embodiments of the application, the exponent influence value includes: leading shift value and mantissa overflow value; the leading shift value characterizes the mantissa of the data to be converted based on the number of leading zeros of the intermediate mantissa bit width; the mantissa overflow value characterizes an overflow value of the mantissa represented by the mantissa of the intermediate data in the target format.
In the embodiment of the present application, in the case where the format to be converted is an integer format, since there may be 0's added to the high order bits in the first shift process, there may also be 0's in the high order bits of the mantissa of the integer format, resulting in leading 0's in the high order bits of the mantissa of the intermediate data. Since the leading 0 does not affect the size of the mantissa value, the leading 0 may be removed to make the first high order significant, thereby obtaining the significant number of the mantissa of the intermediate data that affects the mantissa size. In the case where the format to be converted is a floating point format, the most significant bit is 1 and the number of leading 0 s is 0.
In the embodiment of the present application, since the bit width of the intermediate reduction mantissa may be different from the mantissa bit width of the target format, the mantissa calculation module 202 may intercept the mantissa bit width of the target format of the high order from the intermediate reduction mantissa, and round the mantissa according to the preset rounding mode. During rounding, the number may need to be incremented by 1, resulting in an overflow value for the number, i.e., mantissa overflow value.
In the embodiment of the application, both the mantissa overflow value and the preamble shift value have an effect on the size of the exponent. The index calculation module adjusts the index of the intermediate data according to the index influence value, so that the numerical accuracy of the intermediate reduction index can be improved.
Based on fig. 13, fig. 14 shows a structure of an alternative data conversion device. As shown in fig. 14, the mantissa calculation module 202 may include: a preamble determination module 2021, a second shift module 2022, and a mantissa rounding module 2023. A preamble determination module 2021, configured to determine the number of preambles 0 from mantissas of the intermediate data, to obtain a preamble shift value; a second shift module 2022, configured to perform a second shift process on the mantissa of the intermediate data according to the preamble shift value, the intermediate floating point format, and the target format, to obtain a second shift mantissa; the second shift mantissa includes a truncated mantissa and a redundant mantissa; the truncated mantissa is positioned at the high position of the second shift mantissa, and the bit width is the same as the bit width of the middle mantissa; the mantissa rounding module 2023 is configured to perform a rounding operation according to the redundant mantissa and the truncated mantissa in a first rounding manner, to obtain an intermediate restored mantissa and a mantissa overflow value.
In an embodiment of the present application, the preamble determination module 2021 may determine the number of preambles 0 from mantissas of intermediate data. In some embodiments, the preamble determination module 2021 may identify a value in the mantissa of the intermediate data, read a value of consecutive 0 s starting from the most significant 0, and obtain the preamble shift value. In some embodiments, the preamble determination module 2021 may sequentially bit-wise or, starting from the most significant bit, the number of bits resulting in 0 as the preamble shift value. In some embodiments, the preamble determination module 2021 may be implemented as a preamble 0 Detector (LZD). In the case where the data src to be converted is all 0, an arbitrary value may be returned.
In an embodiment of the present application, the second shift module 2022 may remove the leading 0 of the mantissa of the intermediate data, then intercept the mantissa bits of the target format from the leading 0 of the mantissa bits according to the difference between the intermediate floating point format and the target format, and obtain the intercepted mantissa of the second shift mantissa, where the remaining low bits are used as the redundant mantissa of the second shift mantissa. In some embodiments, the second shift module 2022 may be implemented as a bi-directional shift device, shifting left removable preamble 0; inside the window after right shift is the truncated mantissa, outside the window is the redundant mantissa.
Illustratively, the mantissa bit width of the target format is 3, the mantissa of the intermediate data is 001011, then the second shifted mantissa is 1011, the truncated mantissa is 101, and the redundant mantissa is 1.
In an embodiment of the present application, the mantissa rounding module 2023 may round according to the redundant mantissa and the truncated mantissa, and use the rounded truncated mantissa as an intermediate reduction mantissa, and use the value of the overflow bit of the rounded truncated mantissa as a mantissa overflow value. The first rounding may be rounding or even rounding.
Note that, if the rounded truncated mantissa does not overflow, the mantissa overflow value is 0.
Illustratively, the truncated mantissa is 101, the redundant mantissa is1, and the first rounding is rounding. The mantissa rounding module 2023 may determine that the intermediate reduction mantissa is 110 and the mantissa overflow value is 0.
It will be appreciated that the mantissa calculation module 202 may determine the preamble shift value by the preamble determination module 2021, perform a second shift process by the second shift module 2022 according to the preamble shift value to obtain the truncated mantissa and the redundant mantissa, and determine the intermediate restored mantissa and the mantissa overflow value by 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 reduction mantissa, so that the function of the mantissa calculation module 202 can be improved, and the accuracy of the intermediate reduction mantissa and the intermediate reduction exponent can be further improved.
Based on fig. 14, fig. 15 shows a structure of an alternative data conversion device. As shown in fig. 15, the mantissa rounding module 2023 may include: a round detection block 20231 and a mantissa addition block 20232. Wherein the rounding detection module 20231 is configured to determine, according to the first rounding manner, a rounding-up value according to at least one of the value of the truncated mantissa and the value of the redundant mantissa; the round-up value is used to characterize the added value of the truncated mantissa; the mantissa addition module 20232 is configured to sum the value of the truncated mantissa with the rounded-up value to obtain an intermediate restored mantissa and a mantissa overflow value.
In the embodiment of the present application, the first rounding mode is rounding, and the round detection module 20231 may determine the round-up value according to the value of the redundancy mantissa. The first rounding approach is to even round, and the round detection module 20231 may determine a round-up value from the values of the truncated mantissa and the redundant mantissa.
In some embodiments, mantissa addition module 20232 is implemented as a circuit consisting of one adder, one selector, and overflow detection unit. Here, the number of bits of the adder and the selector may 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. Illustratively, the data to be converted is FP32, the 23-bit mantissa bits are all 1, the overflow detection unit may determine that the mantissa overflow value is 1 if the round-up value is 1, otherwise is 0; the selector is used to select either 1 or 0 as the mantissa overflow value.
It will be appreciated that after the round-up value is determined by the round-up detection module 20231, the round-up value may be added to the value of the truncated mantissa by the mantissa addition module 20232 to obtain an intermediate restored mantissa. In this way, the hardware processing method for determining the intermediate reduction mantissa can be simplified.
In some embodiments of the present application, the first rounding mode is rounding, and the rounding detection module 20231 may determine that the round-up value is 1 if the value of the preset high bit of the redundancy mantissa is greater than the preset rounding threshold; or determining that the round-up value is 0 in the case that the value of the preset high bit of the redundancy mantissa is smaller than the preset rounding threshold.
In the embodiment of the present application, the preset rounding threshold may be determined according to the number of bits of the preset high bits of the redundancy mantissa, which is not limited in the embodiment of the present application.
Illustratively, the redundancy mantissa is 10. The number of bits of the preset high order is 1, and the preset rounding threshold is 1. The round detection module 20231 may compare the most significant bit "1" of the redundant mantissa to a preset round threshold to obtain a comparison result that is the same as the preset round threshold for the most significant bit "1" of the redundant mantissa, thereby determining that the round-up value is 1.
It is appreciated that the round detection module 20231 may determine the round-up value by the redundant mantissa to implement the round-up manner of rounding.
In some embodiments of the present application, the first rounding mode is even rounding, and the rounding detection module 20231 is further configured to determine that the round-up value is 1 if the value of the highest two digits of the redundancy mantissa is greater than the preset rounding threshold; or under the condition that the value of the highest two digits of the redundant mantissa is smaller than a preset rounding threshold value, determining that the rounding-up value is 0; or under the condition that the numerical value of the highest two digits of the redundant mantissa is equal to a preset threshold value and the numerical value of the truncated mantissa is even, determining that the rounding-up value is 0; or in the case that the value of the highest two digits of the redundant mantissa is equal to a preset threshold value and the value of the truncated mantissa is odd, determining that the rounding-up value is 1.
Illustratively, the preset rounding threshold is 10. If the truncated mantissa is 10 and the redundant mantissa is 10, the round detection module 20231 may determine that the round-up value is 0. If the truncated mantissa is 10 and the redundant mantissa is 11, the round detection module 20231 may determine that the round-up value is 1. If the truncated mantissa is 01 and the redundant mantissa is 10, the round detection module 20231 may determine that the round-up value is 1.
In some embodiments, the round detection module 20231 may determine whether a bit following the most significant bit of the redundancy mantissa is 0. If so, determining a rounding-up value according to whether the lowest bit of the truncated mantissa is 0; in the case where the lowest bit of the truncated mantissa is 0, determining that the round-up value is 0; in the case where the lowest order bit of the truncated mantissa is 1, a round-up value of 1 is determined. If the one bit after the most significant bit of the redundancy mantissa is not 0, then a round-up value of 1 is determined.
It is appreciated that the round-off detection module 20231 may determine the round-up value by truncating whether the value of the mantissa is even, enabling a round-off to even mode.
In some embodiments of the present application, the second shift module 2022 is further configured to determine a second shift value according to the preamble shift value, the intermediate floating point format, and the target format; in the case where the second shift value is a positive value, the second shift process is a left shift; in the case where the second shift value is a negative value, the second shift process is a right shift; performing second shift processing on mantissas of the intermediate data according to the second shift value to obtain second shift mantissas of the original codes; and determining a second shift mantissa according to the positive and negative properties of the data to be converted and the original code second shift mantissa.
In an embodiment of the present application, the second shift module 2022 may determine the second shift value according to the preamble shift value, the intermediate floating point format, and the target format; and shifting the mantissa of the intermediate data according to the second shift value to obtain an original code second shift mantissa, and finally, processing the original code second shift mantissa according to the positive and negative properties of the data to be converted to obtain a second shift mantissa. The data to be converted is positive, the second shift mantissa is the original code, the data to be converted is negative, and the second shift mantissa is the complement code.
It will be appreciated that determining the shift direction of the second shift by the positive and negative nature of the second shift value can improve the intelligence of the hardware process.
In some embodiments of the present application, the second shift module 2022 is further configured to take the original code second shift mantissa as the second shift mantissa if the positive and negative properties of the data to be converted are positive numbers; or taking the complement of the second shift mantissa of the original code as the second shift mantissa under the condition that the positive and negative properties of the data to be converted are negative numbers.
It can be understood that, since the data processed previously are all original code data, and if the target format is in a signed format, the mantissa of the floating point format or the number of bits of the integer format except for the sign bit need to be represented by a complement, where the second shift mantissa is determined according to the format of the data to be converted, so that the accuracy of data processing can be improved.
Note that, the second shift value is a signed integer, and when the sign of the second shift value indicates that the second shift value is a negative number, the second shift process is a right shift; in the case where the sign of the second shift value characterizes the second shift value as a positive number, the second shift process is a left shift. Wherein the manner in which the second shift module 2022 determines the second shift value is different for different target formats.
In some embodiments, where the target format is a floating point format, the second shift module 2022 may determine the second shift value based on the leading shift value, the intermediate mantissa bit width, and the mantissa bit width of the target format. Wherein the preamble shift value characterizes the left shift number. The leading shift value 0 in the middle mantissa bit width can be removed by left shift, and then the number of mantissa bit widths in the target format is intercepted from the highest bit of the rest bits to be taken as the intercepting mantissa. Here, the truncated procedure corresponds to right shifting the remaining digits, the right shifted-out digits are redundant mantissas, and the digits other than the redundant mantissas in the remaining mantissas are truncated mantissas.
In some embodiments of the application, the target format is a floating point format; the second shift module 2022 is configured to subtract the difference between the intermediate tail bit width tmat _w and the bit width rmat _w of the target format data by using the preamble shift value lzd to obtain a second shift value rmat _ shf _val, see formula (7).
Rmat _ shf _val= lzd- (tmat _w-rmat _w) formula (7)
The difference between the intermediate mantissa bit width tmat _w and the bit width rmat _w of the target format data is the right shift number in the intercepting process, the second shift value rmat _ shf _val is the difference between the left shift number lzd and the right shift number, and the right shift number is the number of redundant mantissas.
Illustratively, the mantissa of the intermediate data is 0010010, then the preamble 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 shift the mantissa 0010010 of the intermediate data by 1 bit to the right, resulting in the truncated mantissa 1001 and the redundant mantissa 0, and determine the intermediate restored mantissa as 1010 in a way rounded to the even.
It will be appreciated that the mantissa in the intermediate floating point format may be converted to an intermediate reduced mantissa in the floating point format with integer bit 1 at the top by equation (7). In this way, the format conversion of the data to be converted can be realized as long as the intermediate reduction mantissa in the floating point format is continuously reduced to the target format. As the intermediate data in the floating point format is expressed in any floating point format, the intermediate data can be realized by adopting a hardware circuit in the related technology, the hardware realization of the data format conversion device is convenient, and the diversity of the target format can be improved.
In some embodiments, where the target format is an integer format, the second shift module 2022 may determine the second shift value based on 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 exponent bits, the second shift module 2022 needs to shift the mantissa to clear the exponent, and the mantissa after clearing the exponent needs to be truncated or 0 appended at low order to achieve conversion to the mantissa of the target format.
In some embodiments of the application, the target format is an integer format; the second shift module 2022 is further configured to obtain a second shift value by using a difference between the exponent of the intermediate data and the exponent offset of the intermediate floating point format, and the intermediate tail number bit width.
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 left shift number. The difference between the middle mantissa bit widths tmat _w and 1 is the right shift number. The right shift procedure is to shift the highest order integer of the intermediate floating point format to the lowest order of the intermediate reduction 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).
Rmat _ shf _val=texp-tbias- (tmat _w-1) formula (8)
It will be appreciated that the values of the intermediate floating point format may be represented in integer format by equation (8) to effect conversion of the intermediate floating point format to integer format. In this way, the format conversion of the data to be converted can be completed as long as the intermediate reduction mantissa in the integer format is continuously reduced to the target format. The intermediate reduction mantissa is converted into any integer format, so that the intermediate reduction mantissa can be realized by adopting a hardware circuit in the related technology, the hardware realization of the data format conversion device is convenient, and the diversity of target formats can be improved.
Based on fig. 15, fig. 17 shows a structure of an alternative data conversion device. As shown in fig. 17, the restoration module 203 may include: a floating point restoration module 2031, an integer restoration module 2032, and a target format selection module 2033. The floating point reduction module 2031 is configured to reduce the combined number of the intermediate reduction exponent and the intermediate reduction mantissa to floating point format data according to the sign value, the special judgment result and the target format of the intermediate data; an integer reduction module 2032, configured to reduce the intermediate reduction mantissa to integer format data according to the symbol value, the special judgment result, and the target format of the intermediate data; the target format selection module 2033 is configured to determine the floating point format data as target format data in the case where the target format is the floating point format; or in the case that the target format is an integer format, determining the integer format data as the target format data. In some embodiments, the target format selection module may be configured as a selector for selecting one of the integer format data and the floating point format data as the target format data. Here, the number of bits of the selector may be set as needed, and the embodiment of the present application is not limited.
In an embodiment of the present application, the floating-point reduction module 2031 may reduce the combined number of the intermediate reduction exponent and the intermediate reduction mantissa to a target format, where the target format may be any floating-point format of a preset plurality of data formats. Here, the floating point restoration module 2031 also needs to restore the combined number according to the sign value of the intermediate data. In the case where the sign value of the intermediate data characterizes the intermediate data as negative, the mantissa of the floating point format data needs to be the complement number. The floating point restoring module 2031 also needs to determine the floating point format data as a floating point result value matching the floating point special number in the case where the special determination result indicates that the data to be converted is the floating point special number.
Table 1 shows floating point result values corresponding to the first floating point special numbers. Table 2 shows floating point result values corresponding to the second floating point special number.
TABLE 1
First floating point special number Floating point result value
Normal value (denormal number) ±0
Infinity (INF) ±INF
Non-numerical value (NAN) NAN
The absolute value is less than the minimum absolute value representable by the target format ±0
The absolute value is greater than the maximum absolute value representable by the target format ±INF
TABLE 2
Second floating point special number Floating point result value
Non-numerical value (NAN) 0
Positive infinity (+inf) Maximum representable by target format
Negative infinity (-INF) Minimum representable by target format
Greater than the maximum representable by the target format Maximum representable by target format
Less than the minimum representable by the target format Minimum representable by target format
In the embodiment of the present application, when the target format is an integer format, the integer reduction module 2032 may reduce the intermediate reduction mantissa to the target format, where the target format may be any floating point format of a preset plurality of data formats. Here, the integer reduction module 2032 also needs to reduce the combination number according to the sign value of the intermediate data. In the case where the sign value of the intermediate data characterizes the intermediate data as negative, the mantissa of the integer format data needs to be a complement number. The integer reduction module 2032 also needs to determine the integer format data as an integer result value matching the integer special number in the case where the special determination result characterizes the data to be converted as the integer special number.
Table 3 shows the integer result values corresponding to the first integer special number. Table 4 shows the integer result values corresponding to the second integer special number.
TABLE 3 Table 3
First integer special number Integer result value
0 0
Greater than the maximum positive number representable by the target format INF
Less than the minimum negative representable by the target format INF
TABLE 4 Table 4
Second integer special number Integer result value
Greater than the maximum positive number representable by the target format Maximum representable by target format
Less than the minimum negative representable by the target format Minimum representable by target format
It will be appreciated that after conversion processing is performed by the floating point reduction module 2031 and the integer reduction module 2032, one output may be selected from the numbers obtained by the two modules by the target format selection module 2033. The reduction processing efficiency of the reduction module 203 can be improved.
In some embodiments of the present application, the floating point recovery module 2031 is further configured to determine, as the target format data, a floating point result value corresponding to the floating point special number if the special determination result indicates that the data to be converted is the floating point special number; the floating point restoring module 2031 is further configured to perform, when the special determination result indicates that the data to be converted is not a floating point special number and the target format is the first floating point format, a first floating point restoring process on the combined number of the intermediate restoring exponent and the intermediate restoring mantissa according to the sign value of the intermediate data, to obtain floating point format data in the first floating point format.
In the embodiment of the present application, the floating point recovery module 2031 may first determine whether the special determination result indicates that the data to be converted is a floating point special number, and if so, directly determine a floating point result value corresponding to the floating point special number as the floating point format data; otherwise, according to the sign value of the intermediate data, carrying out first floating point reduction processing on the combined number to obtain a floating point format number in a first floating point format. The first floating point format is one of floating point formats; the first floating point format is one of a plurality of preset data formats.
It can be understood that, the floating point restoring module 2031 determines whether the special determination result indicates that the data to be converted is a floating point special number, and may directly determine the floating point result value corresponding to the floating point special number as the floating point format data when the special determination result indicates that the data to be converted is the floating point special number; without reducing the combined number, the reduction efficiency of the floating point reduction module 2031 can be improved.
In some embodiments of the present application, the integer second conversion module 2032 is further configured to determine, as the target format data, an integer result value corresponding to the integer special number if the special determination result indicates that the data to be converted is the integer special number; the integer second conversion module 2032 is further configured to, when the special determination result indicates that the data to be converted is not an integer special number and the target format is the first integer format, perform a first integer reduction process on the combined value of the intermediate reduction exponent and the intermediate reduction mantissa according to the sign value of the intermediate data, to obtain the integer format data in the first integer format.
In the embodiment of the present application, the integer reduction module 2032 may first determine whether the special determination result represents that the data to be converted is an integer special number, and if so, directly determine an integer result value corresponding to the integer special number as the integer format data; otherwise, according to the symbol value of the intermediate data, performing first integer reduction processing on the intermediate reduction mantissa to obtain an integer format number in a first integer format. Wherein the first integer format is one of integer formats; the first integer format is one of a plurality of preset data formats.
It can be understood that, because the integer reduction module 2032 determines whether the special determination result indicates 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 the integer format data when the special determination result indicates that the data to be converted is the integer special number; without reducing the intermediate reduction mantissa, the reduction efficiency of the integer reduction module 2032 can be improved.
Based on the above data conversion device, fig. 18 shows an alternative data conversion method, as shown in fig. 18, which may include:
S101, converting data to be converted of any one of a plurality of preset data formats into intermediate data of an intermediate floating point format; the bit width of the middle exponent of the middle floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to a plurality of preset formats; the middle mantissa bit width of the middle floating point format is the maximum value of bit widths of a plurality of configuration mantissas corresponding to a plurality of preset data formats; the bit width of the configuration index for 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 accuracy of the data format.
S102, converting the intermediate data into target format data according to a conversion mode matched with the target format data; the target format of the target format data is any one of a plurality of preset data formats.
In some embodiments, before converting the data to be converted in any one of the preset multiple data formats into the intermediate data in the intermediate floating point format in S101, the method further includes: acquiring the bit width of the configuration index and the bit width of the configuration mantissa of each data format in the preset plurality of data formats through an acquisition module; and determining, by a determining module, a maximum value of bit widths of configuration indexes of the plurality of data formats as the intermediate exponent bit width, and determining a maximum value of configuration mantissa bit widths of the plurality of data formats as the intermediate mantissa bit width.
In some embodiments, the preset plurality of data formats includes a floating point format; the method further comprises the steps of: the bit width of the exponent bits in the floating point format is used as the configuration exponent bit width of the floating point format through the acquisition module; and determining the configuration 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.
In some embodiments, the preset plurality of data formats includes an integer format; the method further comprises the steps of: determining, by the acquisition module, an intermediate bit width based on all bit widths of the integer format; determining a bit width of a configuration index of the integer format based on the intermediate bit widths; and taking the whole bit width of the integer format as the bit width of the configuration mantissa of the integer format.
In some embodiments, the method for converting the data to be converted in any one of the preset multiple data formats into the intermediate data in the intermediate floating point format in S101 further includes: judging whether the data to be converted is a preset special number or not according to the format to be converted of the data to be converted, the target format and the judgment of the preset special number by a special judgment module to obtain a special judgment result; and converting 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 by an exponent mantissa conversion module to obtain the intermediate data.
In some embodiments, the method further comprises: converting the index of the data to be converted according to the conversion offset difference value between the intermediate floating point format and the format to be converted and the special judgment result by an index conversion module to obtain the index of the intermediate data; and converting 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 by a mantissa conversion module to obtain the mantissa of the intermediate data.
In some embodiments, the method further comprises: obtaining an index to be determined of intermediate data through the conversion offset difference value and the data to be converted by a first index conversion module; and determining the index of the intermediate data according to the special judgment result and the index to be determined through a second index conversion module.
In some embodiments, the method further comprises: the conversion offset difference value is obtained through a conversion offset difference value obtaining module; extracting an index of the data to be converted through an index extraction module; and adding the index of the data to be converted and the conversion offset difference value through an index adding module to obtain the index to be determined.
In some embodiments, the method further comprises: determining an offset difference value matched with the format of the data to be converted from preset offset difference values by the conversion offset difference value acquisition module, and taking the offset difference value as the conversion offset difference value; the preset offset includes a difference between an exponent offset of each of the preset plurality of data formats and an exponent offset of the intermediate floating point format.
In some embodiments, the method further comprises: acquiring an index offset of the intermediate floating point format and an index offset of the format to be converted through an offset acquisition module; and taking 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 through an offset difference value determining module.
In some embodiments, the method further comprises: determining an index offset of the intermediate floating point format according to the intermediate index bit width of the intermediate floating point format through the offset acquisition module; and determining the index offset of the format to be converted according to the configuration index bit width of the format to be converted.
In some embodiments, the method further comprises: determining a preset special index value as an index of the intermediate data by the second index conversion module under the condition that the special judgment result represents that the data to be converted is a preset special number; or determining the index to be determined as the index of the intermediate data under the condition that the special value judgment result represents that the data to be converted is not the preset special number; the preset special number includes a non-formatted floating point number or an integer 0.
In some embodiments, the method further comprises: performing first shift processing on mantissas of the data to be converted according to the format to be converted and the intermediate floating point format by a first mantissa conversion module to obtain mantissas to be determined of the intermediate data; the bit width of the mantissa to be determined is the intermediate mantissa bit width; 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.
In some embodiments, the method further comprises: extracting mantissas to be shifted from the data to be converted according to the format to be converted through a mantissa extraction module; the mantissa to be shifted is original code data; and performing first shifting processing on the mantissa to be shifted according to the format to be converted through a first shifting module to obtain the mantissa to be determined.
In some embodiments, the method further comprises: the mantissa of the data to be converted is subjected to absolute value processing through a positive processing module, so that a positive mantissa is obtained; determining the mantissa of the data to be converted as the mantissa to be shifted under the condition that the positive and negative properties represent that the data to be converted is positive; or determining the positive mantissa as the mantissa to be shifted if the positive and negative properties characterize the data to be converted as negative.
In some embodiments, the format of the data to be converted is a floating point format; the method further comprises the steps of: splicing the highest bit of the mantissa to be shifted with the integer bit of the floating point format through the first shifting module to obtain a floating point decimal; and taking the decimal mantissa as the highest bit of the mantissa to be determined, and supplementing 0 to the rest low bits.
In some embodiments, the format of the data to be converted is an integer format; the method further comprises the steps of: and taking the mantissa to be shifted as the lowest bit of the mantissa to be determined through the first shifting module, and supplementing 0 to the rest high bits.
In some embodiments, the method further comprises: determining a preset special mantissa value as the mantissa of the intermediate data by the second mantissa conversion module under the condition that the special judgment result represents that the data to be converted is a preset special number; or determining the mantissa to be determined as the mantissa of the intermediate data under the condition that the special judgment result represents that the data to be converted is not the preset special number; the preset special number includes a non-formatted floating point number or an integer 0.
In some embodiments, the method further comprises: adding an index influence value generated in the mantissa calculation process with the index of the intermediate data through an index calculation module to obtain an intermediate reduction index; performing 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 by a mantissa calculation module to obtain an intermediate reduction mantissa; the bit width of the intermediate reduction mantissa is the same as the mantissa bit width of the target format; and carrying out reduction processing on the mantissa values combined by the intermediate reduction exponent and the intermediate reduction mantissa according to the target format and the special judgment result by a reduction module to obtain the target format data.
In some embodiments, the exponent influence value includes: leading shift value and mantissa overflow value; the preamble shift value characterizes a number of preamble zeros of the intermediate tail bit width; the mantissa overflow value characterizes an overflow value of the mantissa of the intermediate data as represented by the target format.
In some embodiments, the method further comprises: determining the number of the leading 0 from the mantissa of the intermediate data through a leading determining module to obtain the leading shift value; performing 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 by a second shift module to obtain a second shift mantissa; the second shift mantissa includes a truncated mantissa and a redundant mantissa; the truncated mantissa is located at a high position of the second shifted mantissa, and a bit width is the same as the intermediate mantissa bit width; and rounding the intercepted mantissa according to the redundant mantissa in a first rounding mode through a mantissa rounding module to obtain the intermediate reduction mantissa and the mantissa overflow value.
In some embodiments, the method further comprises: determining, by a rounding detection module, a round-up value according to the first rounding mode, according to at least one of the value of the truncated mantissa and the value of the redundant mantissa; the rounding-up value is used for representing an added value of the numerical value of the truncated mantissa; and summing the numerical value of the intercepted mantissa and the rounding-up value through a mantissa addition module to obtain the intermediate reduction mantissa and the mantissa overflow value.
In some embodiments, the method further comprises: determining, by the rounding detection module, that the round-up value is 1 if the value of the highest two bits of the redundancy mantissa is greater than a preset rounding threshold; or determining that the round-up value is 0 if the value of the highest two digits of the redundancy mantissa is less than the preset rounding threshold; or determining that the rounding-up value is 0 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 even; or determining that the rounding-up value is 1 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 odd.
In some embodiments, the method further comprises: determining, by the rounding detection module, that the round-up value is 1 if a value of a preset high bit of the redundancy mantissa is greater than or equal to a preset rounding threshold; or in the case that the value of the preset high bit of the redundancy mantissa is smaller than the preset rounding threshold value, determining that the rounding-up value is 0.
In some embodiments, the method further comprises: determining, by the second shift module, a second shift value according to the preamble shift value, the intermediate floating point format, and the target format; in the case where the second shift value is a positive value, the second shift process is a left shift; in the case where the second shift value is a negative value, the second shift process is a right shift; performing the second shift processing on the mantissa of the intermediate data according to the second shift value to obtain an original code second shift mantissa; and determining a second shift mantissa according to the positive and negative properties of the data to be converted and the original code second shift mantissa.
In some embodiments, the method further comprises: taking the original code second shift mantissa as the second shift mantissa under the condition that the positive and negative properties of the data to be converted are positive numbers through the second shift module; or taking the complement of the original code second shift mantissa as the second shift mantissa under the condition that the positive and negative properties of the data to be converted are negative numbers.
In some embodiments, the target format is a floating point format; the method further comprises the steps of: and obtaining the second shift value by the second shift module by utilizing the difference value of the leading shift value, the intermediate tail digital width and the bit width of the target format data.
In some embodiments, the target format is an integer format; the method further comprises the steps of: and obtaining the second shift value by using the difference value between the exponent of the intermediate data and the exponent offset of the intermediate floating point format and the intermediate tail number bit width through the second shift module.
In some embodiments, the method further comprises: the combined value of the intermediate reduction exponent and the intermediate reduction mantissa is reduced to floating point format data by a floating point reduction module according to the sign value of the intermediate data, the special judgment result and the target format; the intermediate reduction mantissa is reduced to be the data in the integer format according to the symbol value of the intermediate data, the special judgment result and the target format through an integer reduction module; determining, by a target format selection module, the floating point format data as the target format data in the case that the target format is a floating point format; or in the case that the target format is an integer format, determining the integer format data as the target format data.
In some embodiments, the method further comprises: determining a floating point result value corresponding to the floating point special number as the floating point format data by the floating point restoring module under the condition that the special judgment result represents that the data to be converted is the floating point special number; or under the condition that 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, carrying out first floating point reduction processing on the combined number of the intermediate reduction exponent and the intermediate reduction mantissa according to the sign value of the intermediate data to obtain the floating point format data of the first floating point format.
In some embodiments, the method further comprises: determining, by the integer reduction module, an integer result value corresponding to the integer special number as the target format data when the special determination result characterizes the data to be converted as the integer special number; or under the condition that the special judgment result represents that the data to be converted is not the special number and the target format is the first integer format, carrying out first integer reduction processing on the combined value of the intermediate reduction exponent and the intermediate reduction mantissa according to the symbol value of the intermediate data to obtain the integer format data in the first integer format.
Fig. 19 shows a structure of an electronic device according to an embodiment of the present application, and as shown in fig. 19, the electronic device 170 includes a memory 1707, a processor 1708, and a computer program stored on the memory 1707 and executable on the processor 1708; wherein the processor 1708 is configured to execute the data format conversion method according to the foregoing embodiment when executing the computer program.
It is to be appreciated that the electronic device 170 also includes a bus system 1709; the various components in the electronic device 170 are coupled together by a bus system 1709. It is appreciated that the bus system 1709 is used to facilitate connected communications between these components. The bus system 1709 includes a power bus, a control bus, and a status signal bus in addition to the data bus.
It will be appreciated that the memory in embodiments of the application may be either volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. Wherein the nonvolatile Memory may be Read-Only Memory (ROM), programmable Read-Only Memory (Programmable Read-Only Memory, PROM), erasable programmable Read-Only Memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable programmable Read-Only Memory (ELECTRICALLY ERASABLE PROGRAMMABLE READ-Only Memory, EEPROM), magnetic random access Memory (Ferromagnetic Random Access Memory, FRAM), flash Memory (Flash Memory), magnetic surface Memory, optical disk, or Read-Only optical disk (Compact Disc Read-Only Memory, CD-ROM); the magnetic surface memory may be a disk memory or a tape memory. The volatile memory may be random access memory (Random Access Memory, RAM) which acts as external cache memory. By way of example, and not limitation, many forms of RAM are available, such as static random access memory (Static Random Access Memory, SRAM), synchronous static random access memory (Synchronous Static Random Access Memory, SSRAM), dynamic random access memory (Dynamic Random Access Memory, DRAM), synchronous dynamic random access memory (Synchronous Dynamic Random Access Memory, SDRAM), double data rate synchronous dynamic random access memory (Double Data Rate Synchronous Dynamic Random Access Memory, ddr SDRAM), enhanced synchronous dynamic random access memory (Enhanced Synchronous Dynamic Random Access Memory, ESDRAM), synchronous link dynamic random access memory (SYNCLINK DYNAMIC Random Access Memory, SLDRAM), direct memory bus random access memory (Direct Rambus Random Access Memory, DRRAM). The memory described by embodiments of the present application is intended to comprise, without being limited to, these and any other suitable types of memory.
The method disclosed by the embodiment of the application can be applied to a processor or realized by the processor. The processor may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or by instructions in the form of software. The processor may be a general purpose processor, DSP, or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The processor may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present application. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in the embodiment of the application can be directly embodied in the hardware of the decoding processor or can be implemented by combining hardware and software modules in the decoding processor. The software module may be located in a storage medium, the storage medium being located in a memory, the processor reading signals in the memory, the steps of the method being performed in combination with its hardware.
Embodiments of the present application provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the above method.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above described device embodiments are only illustrative, e.g. the division of the modules is only one logical function division, and there may be other divisions in practice, such as: multiple modules or components may be combined, or may be integrated into another system, or some features may be omitted, or not performed. In addition, the various components shown or discussed may be coupled or directly coupled or communicatively coupled to each other via some interface, whether indirectly coupled or communicatively coupled to devices or modules, whether electrically, mechanically, or otherwise.
The foregoing is merely exemplary embodiments of the present application and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims (26)

1. A data format conversion apparatus, comprising:
The first conversion module is used for converting the data to be converted of any one of a plurality of preset data formats into intermediate data of an intermediate floating point format; the bit width of the middle exponent of the middle floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to the preset various formats; the middle mantissa bit width of the middle floating point format is the maximum value of bit widths of a plurality of configuration mantissas corresponding to the preset various data formats; the bit width of the configuration index 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 accuracy of the data format;
the second conversion module is used for converting the intermediate data into the target format data according to a conversion mode matched with the target format data; the target format of the target format data is any one of the preset multiple data formats.
2. The apparatus of claim 1, wherein the apparatus further comprises:
The acquisition module is used for acquiring the bit width of the configuration index and the bit width of the configuration mantissa of each data format in the preset plurality of data formats;
and the determining module is used for determining the maximum value in the bit widths of the configuration indexes of the plurality of data formats as the middle exponent bit width and determining the maximum value in the configuration tail bit widths of the plurality of data formats as the middle tail bit width.
3. The apparatus of claim 2, wherein the predetermined plurality of data formats includes a floating point format;
The acquisition module is further configured to use a bit width of the exponent bits in the floating point format as a configuration exponent bit width of the floating point format; and determining the configuration 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 apparatus of claim 2, wherein the predetermined plurality of data formats comprises an integer format;
The acquisition module is further used for determining an intermediate bit width based on all bit widths of the integer format;
Determining a bit width of a configuration index of the integer format based on the intermediate bit widths; and taking the whole bit width of the integer format as the bit width of the configuration mantissa of the integer format.
5. The apparatus of any one of claims 1-4, wherein the first conversion module comprises:
The special judging module is used for judging whether the data to be converted is a preset special number according to the format to be converted of the data to be converted and the target format to obtain a special judging result;
and the exponent mantissa conversion module is used for converting 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 apparatus of claim 5, wherein the exponent mantissa conversion module comprises:
the index conversion module is used for carrying out conversion processing on the index of the data to be converted according to the conversion offset difference value between the intermediate floating point format and the format to be converted and the special judgment result to obtain the index of the intermediate data;
And the mantissa conversion module is used for carrying out conversion processing on 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 apparatus of claim 6, wherein the exponential transformation module comprises:
The first index conversion module is used for obtaining an index to be determined of the intermediate data through the conversion offset difference value and the data to be converted;
And the second index conversion module is used for determining the index of the intermediate data according to the special judgment result and the index to be determined.
8. The apparatus of claim 7, wherein the device comprises a plurality of sensors,
The second exponent conversion module is further configured to determine a preset special exponent value as an exponent of the intermediate data when the special determination result indicates that the data to be converted is the preset special number; or determining the index to be determined as the index of the intermediate data under the condition that the special value judgment result represents that the data to be converted is not the preset special number; the preset special number includes a non-formatted floating point number or an integer 0.
9. The apparatus of claim 6, wherein the mantissa conversion module comprises:
The first mantissa conversion module is used for carrying out first shift processing on mantissas of the data to be converted according to the format to be converted and the intermediate floating point format to obtain mantissas to be determined of the intermediate data; the bit width of the mantissa to be determined is the intermediate mantissa bit width;
And the second mantissa conversion module is used for determining the mantissa of the intermediate data according to the special judgment result and the mantissa to be determined.
10. The apparatus of claim 9, wherein the first mantissa conversion module comprises:
The mantissa extraction module is used for extracting mantissas to be shifted from the data to be converted according to the format to be converted; the mantissa to be shifted is original code data;
And the first shifting module is used for carrying out first shifting processing on the mantissa to be shifted according to the format to be converted to obtain the mantissa to be determined.
11. The apparatus of claim 10, wherein the mantissa extraction module comprises:
the positive processing module is used for carrying out absolute value processing on the mantissa of the data to be converted to obtain a positive mantissa;
The extraction mantissa selection module is used for determining the mantissa of the data to be converted as the mantissa to be shifted under the condition that the positive and negative properties represent that the data to be converted is positive; or determining the positive mantissa as the mantissa to be shifted if the positive and negative properties characterize the data to be converted as negative.
12. The apparatus of claim 10, wherein the format of the data to be converted is a floating point format;
The first shifting module is further configured to splice the highest bit of the mantissa to be shifted to the integer bit of the floating point format to obtain a floating point decimal; and taking the decimal mantissa as the highest bit of the mantissa to be determined, and supplementing 0 to the rest low bits.
13. The apparatus of claim 12, wherein the format of the data to be converted is an integer format;
The first shift module is further configured to use the mantissa to be shifted as a lowest bit of the mantissa to be determined, and complement other high bits by 0.
14. The apparatus of claim 9, wherein the device comprises a plurality of sensors,
The second mantissa conversion module is further configured to determine a preset special mantissa value as the mantissa of the intermediate data when the special judgment result indicates that the data to be converted is the preset special number; or determining the mantissa to be determined as the mantissa of the intermediate data under the condition that the special judgment result represents that the data to be converted is not the preset special number; the preset special number includes a non-formatted floating point number or an integer 0.
15. The apparatus of any one of claims 1-4, wherein the second conversion module comprises:
The exponent calculation module is used for adding an exponent influence value generated in the mantissa calculation process to the exponent of the intermediate data to obtain an intermediate reduction exponent;
The mantissa calculation module is used for carrying out 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 to obtain an intermediate restored mantissa; the bit width of the intermediate reduction mantissa is the same as the mantissa bit width of the target format;
and the reduction module is used for carrying out reduction processing on the mantissa values combined by the intermediate reduction exponent and the intermediate reduction mantissa according to the target format and the special judgment result to obtain the target format data.
16. The apparatus of claim 15, wherein the exponent influence value includes: leading shift value and mantissa overflow value; the preamble shift value characterizes a number of preamble zeros of the intermediate tail bit width; the mantissa overflow value characterizes an overflow value of the mantissa of the intermediate data as represented by the target format.
17. The apparatus of claim 16, wherein the mantissa calculation module comprises:
The preamble determining module is used for determining the number of the preambles 0 from the mantissas of the intermediate data to obtain the preamble shift value;
The second shift module is used for carrying out 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 to obtain a second shift mantissa; the second shift mantissa includes a truncated mantissa and a redundant mantissa; the truncated mantissa is located at a high position of the second shifted mantissa, and a bit width is the same as the intermediate mantissa bit width;
and the mantissa rounding module is used for rounding the intercepted mantissa according to the redundant mantissa in a first rounding mode to obtain the intermediate reduction mantissa and the mantissa overflow value.
18. The apparatus of claim 17, wherein the mantissa rounding module comprises:
The rounding detection module is used for determining a rounding-up value according to at least one of the numerical value of the truncated mantissa and the numerical value of the redundant mantissa in the first rounding mode; the rounding-up value is used for representing an added value of the numerical value of the truncated mantissa;
And the mantissa addition module is used for summing the numerical value of the intercepted mantissa and the rounding-up value to obtain the intermediate restored mantissa and the mantissa overflow value.
19. The apparatus of claim 17, wherein the device comprises a plurality of sensors,
The second shift module is further configured to determine a second shift value according to the preamble shift value, the intermediate floating point format, and the target format; in the case where the second shift value is a positive value, the second shift process is a left shift; in the case where the second shift value is a negative value, the second shift process is a right shift;
performing the second shift processing on the mantissa of the intermediate data according to the second shift value to obtain an original code second shift mantissa;
and determining a second shift mantissa according to the positive and negative properties of the data to be converted and the original code second shift mantissa.
20. The apparatus of claim 19, wherein the device comprises a plurality of sensors,
The second shift module is further configured to use the original code second shift mantissa as the second shift mantissa when the positive and negative properties of the data to be converted are positive numbers; or taking the complement of the original code second shift mantissa as the second shift mantissa under the condition that the positive and negative properties of the data to be converted are negative numbers.
21. The apparatus of claim 19, wherein 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 value between the preamble shift value, the intermediate mantissa bit width and the bit width of the target format data.
22. The apparatus of claim 19, wherein the target format is an integer format;
The second shift module is further configured to obtain the second shift value by using a difference between the exponent of the intermediate data and the exponent offset of the intermediate floating point format, and the intermediate tail number bit width.
23. The apparatus of claim 15, wherein the reduction module comprises:
the floating point restoring module is used for restoring the combined value of the intermediate restoring exponent and the intermediate restoring mantissa into floating point format data according to the symbol value of the intermediate data, the special judging result and the target format;
The integer reduction module is used for reducing the intermediate reduction mantissa into integer format data according to the symbol value of the intermediate data, the special judgment result and the target format;
The target format selection module is used for determining the floating point format data as the target format data under the condition that the target format is a floating point format; or in the case that the target format is an integer format, determining the integer format data as the target format data.
24. A method of data format conversion, comprising:
Converting the data to be converted of any one of a plurality of preset data formats into intermediate data of an intermediate floating point format; the bit width of the middle exponent of the middle floating point format is the maximum value of the bit widths of a plurality of configuration exponents corresponding to the preset various formats; the middle mantissa bit width of the middle floating point format is the maximum value of bit widths of a plurality of configuration mantissas corresponding to the preset various data formats; the bit width of the configuration index 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 accuracy of the data format;
According to a conversion mode matched with the target format data, converting the intermediate data into 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, comprising:
A memory for storing a computer program;
A processor for performing the data format conversion method of claim 24 when the computer program runs.
26. A computer storage medium having stored thereon executable instructions for implementing the data format conversion method of claim 24 when executed by a processor.
CN202410267651.0A 2024-03-08 2024-03-08 Data format conversion device and method, electronic device, and computer storage medium Pending CN118051200A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410267651.0A CN118051200A (en) 2024-03-08 2024-03-08 Data format conversion device and method, electronic device, and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410267651.0A CN118051200A (en) 2024-03-08 2024-03-08 Data format conversion device and method, electronic device, and computer storage medium

Publications (1)

Publication Number Publication Date
CN118051200A true CN118051200A (en) 2024-05-17

Family

ID=91048258

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410267651.0A Pending CN118051200A (en) 2024-03-08 2024-03-08 Data format conversion device and method, electronic device, and computer storage medium

Country Status (1)

Country Link
CN (1) CN118051200A (en)

Similar Documents

Publication Publication Date Title
US8719322B2 (en) Floating point format converter
US8874630B2 (en) Apparatus and method for converting data between a floating-point number and an integer
KR102581403B1 (en) Shared hardware logic unit and method for reducing die area
Hormigo et al. Measuring improvement when using HUB formats to implement floating-point systems under round-to-nearest
CN111813375A (en) Modulo arithmetic processing method and related product
US20150113027A1 (en) Method for determining a logarithmic functional unit
US20010025293A1 (en) Divider
US9009209B2 (en) Processor, control method of processor, and computer readable storage medium storing processing program for division operation
CN113126954B (en) Method, device and arithmetic logic unit for floating point number multiplication calculation
US10216481B2 (en) Digit recurrence division with scaling and digit selection using intermediate value
CN106997284B (en) Method and device for realizing floating point operation
CN118051200A (en) Data format conversion device and method, electronic device, and computer storage medium
CN114201140B (en) Exponential function processing unit, method and neural network chip
CN112394904B (en) Floating point data processing method, arithmetic unit and electronic equipment
CN115268832A (en) Floating point number rounding method and device and electronic equipment
CN115483934A (en) Data conversion method and device for multi-party security calculation
CN111538474B (en) Division and evolution operation processor and operation processing system of Posit floating point number
US5754458A (en) Trailing bit anticipator
CN117422807B (en) Color value determining method and device, electronic equipment and computer storage medium
EP0332215A2 (en) Operation circuit based on floating-point representation
CN112783470A (en) Device and method for executing floating point logarithm operation
CN113377334B (en) Floating point data processing method and device and storage medium
KR20150107614A (en) A data processing apparatus and method for performing a shift function on a binary number
US4716538A (en) Multiply/divide circuit for encoder PCM samples
US20230325150A1 (en) Multiple-input floating-point number processing method and apparatus

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination