[0053] The technical solutions in the embodiments of the present invention will be described clearly and completely in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
[0054] The embodiment of the present invention provides a method for division operation based on FPGA, such as figure 1 As shown, the method includes:
[0055] S101: Acquire a first data item that is used as a divisor in the division operation and expressed in decimal notation.
[0056] S102: Determine whether the first data item is the same as the preset data item in the storage table containing the reciprocal of the setting data item, if yes, proceed to S103, if not, proceed to S104.
[0057] Specifically, in the embodiment of the present invention, a storage table storing the reciprocal of the set data items is preset, and the range of the data items stored in the storage table can be flexibly adjusted according to the actual required calculation accuracy. In the embodiment of the present invention, Store as few data items as possible, and make the calculation result unique, set 2 i To 2 i+1 The reciprocal of the integer between -1 is the reciprocal of the setting data item in the storage table and is stored in the storage table, where i is the corresponding power value when the storage data item is determined in the storage table, and the value of i is i=0 , 1, 2, 3,..., 32.
[0058] Further, in the embodiment of the present invention, Table 1 lists the data ranges that may be selected, and Table 1 lists the selected data ranges, the number of stored data items, and the corresponding relationship between the calculation errors, and the stored data is comprehensively considered The relationship between the term and the calculation error, in the embodiment of the present invention, it is preferable to use 2 5 To 2 6 The reciprocal of the integer between -1 (32 to 63) is stored in the storage table as the reciprocal of the setting data item in the storage table. Of course, the embodiment of the present invention does not limit it. If higher calculation accuracy is required, You can use the reciprocal of an integer between (64 to 127) or (128 to 255) as the reciprocal of the setting data item in the storage table.
[0059] data range
[0060] 128 to 255
[0061] Table 1
[0062] S103: Call the reciprocal of the same data item in the storage table as the first data item as the reciprocal of the first data item.
[0063] S104: Perform a shift operation on the first data item to obtain a second data item that can be found in the storage table, and determine the reciprocal of the first data item according to the second data item.
[0064] Specifically, in the embodiment of the present invention, the first data item is converted to binary and the shift operation is performed, so that the corresponding decimal data item after the shift operation can find the corresponding second data item in the storage table and call the storage table For the reciprocal of the second data item, convert the reciprocal of the second data item to binary, and perform a reverse shift operation of the same number of bits to obtain the reciprocal of the first data item.
[0065] Preferably, in the embodiment of the present invention, the first data item is converted to binary and the shift operation is performed, so that the corresponding decimal data item after the shift operation can find the corresponding second data item in the storage table. The following methods can be used :
[0066] A. Convert the first data item to binary to obtain the first data item in binary representation;
[0067] B. Using the formula X=[log 2 M]-i, determine the number of bits to be shifted, where M is the first data item, X is the number of bits to be shifted, and the symbol [] represents rounding down, and i corresponds to when the data item is determined to be stored in the storage table in S102 The value of i is the same;
[0068] C. Shift the first data item expressed in binary by X bits in the forward direction to obtain the second data item.
[0069] The positive shift in the embodiment of the present invention refers to the shift direction of the second data item obtained from the first data item. The shift direction is related to the sign of X determined in B. When X is a positive number, it means to the right. Move, when X is negative, it means move to the left.
[0070] After the second data item is obtained in the embodiment of the present invention, the reciprocal of the second data item can be searched in the storage table, and the reciprocal of the second data item can be converted into binary and then reversely shifted by X bits to obtain the binary representation The reciprocal of the first data item of, and then the decimal conversion, you can get the reciprocal of the first data item.
[0071] In the embodiment of the present invention, the reverse shift refers to the shift direction when the first data item is obtained from the second data item.
[0072] further, figure 2 Shown is the calculation error diagram of the division operation using straight line fitting in the embodiment of the present invention, which is represented by figure 2 It can be seen that when the divisor n is small, the error of the straight line fitting is larger. As the divisor n increases, the error will continue to decrease. Therefore, in the embodiment of the present invention, in order to further improve the calculation accuracy, the reciprocal of the second data item can be obtained. After that, the reciprocal of adjacent data items in the storage table is further used to linearly interpolate the decimal part of the reciprocal of the second data item to obtain the corrected value of the reciprocal of the first data item, and the reciprocal of the second data item stored in the storage table The data item obtained after converting to binary and performing a reverse shift operation of the same number of bits is used as the reference value of the reciprocal of the first data item, and finally the sum of the correction value and the reference value is used as the final reciprocal of the first data item.
[0073] Specifically, in the embodiment of the present invention, the process of performing linear interpolation to obtain the correction value of the first data item may adopt ((a[N+1]-a[N])*(M-(N< >(X*2) method performs linear interpolation to obtain the correction value of the reciprocal of the first data item, where a[N] is the reciprocal of the second data item, and a[N+1] is the data adjacent to the second data item The reciprocal of the item, M is the first data item, (N<>(X*2) means the forward shift is 2X bits, and X is The number of bits to shift.
[0074] S105: Multiply the reciprocal of the first data item by the data item used as the dividend in the division operation to complete the division operation.
[0075] In the embodiments of the present invention, the above method of determining the reciprocal of the divisor will be described in detail below in conjunction with specific applications.
[0076] In the embodiment of the present invention, the setting data item stored in the setting storage table is the reciprocal of an integer between 25 and 26-1, then i=5 at this time.
[0077] For example, when the first data item M as the divisor M=6000, the first data item M of the binary representation obtained after 6000 binary conversion is 1011101110000, and then according to X=[log 2 M]-i, determine the number of bits to be shifted, X=7, shift 1011101110000 to the right by 7 digits, get the second data item 101110 in binary representation, and convert it to decimal, then N=46.
[0078] At this time, the reciprocal a[46] corresponding to 46 found in the storage table is converted into binary and shifted by the same number of bits in the reverse direction to obtain the reference value, which can be expressed as: reference value = a[46] < <7=1.6984e-004
[0079] Use the formula ((a[N+1]-a[N])*(M-(N<>(X*2) to perform linear interpolation, and the obtained correction value can be expressed as: correction value =((a[47]-a[46])*112)> > 14=-3.1621e-006
[0080] f(1/6000)=reference value+correction value=1.66675e-004 (32-bit precision)
[0081] And 1/6000=1.6667e-004, so the error=8.1764e-009 (the 32-bit precision error is 10-9 ).
[0082] In another embodiment, when the first data item as the divisor M=3, the first data item M in the binary representation obtained after the binary conversion of 3 is 00000011, and then according to X=[log 2 M]-i, determine the number of bits to shift, you can get X=-4, shift 00000011 to the left by 4 digits, get the second data item 00110000 in binary representation, convert to decimal, then N=48.
[0083] At this time, the reference value = a[48] < <(-4)=0.3333333321
[0084] Correction value=((a[49]-a[48])*0)> > (-8)=0
[0085] f(1/3)=reference value+correction value=0.3333333321 (32-bit precision)
[0086] And 1/3=0.3333, so the error=1.2418e-009 (the error is 10-9 ).
[0087] In the method for division operation based on FPGA provided by the embodiment of the present invention, by storing the reciprocal of preset data items in the storage table, there is no need to store all the data items, which reduces resource consumption, and when performing division operations, it is judged as the divisor If the first data item is in the preset storage table, if yes, directly call the reciprocal of the data item stored in the storage table, if not, use the shift operation method to determine the second data item in the storage table, and pass the first The two data items determine the reciprocal of the first data item as the divisor, which expands the numerical range of division operations in FPGA.
[0088] On the other hand, the embodiment of the present invention also provides a device for division operation based on FPGA, such as image 3 As shown, the device includes a storage unit 1, a divisor acquisition unit 2, a reciprocal determination unit 3, and an arithmetic unit 4, wherein,
[0089] The storage unit 1 is used to store the reciprocal of the set data item in the storage table in advance.
[0090] The divisor obtaining unit 2 is used to obtain the first data item used as the divisor in the division operation.
[0091] The reciprocal determining unit 3 is used to determine whether the first data item is the same as the data item in the storage table preset in the storage unit 1 and containing the reciprocal of the set data item. If so, directly call the storage table with the The reciprocal of a data item with the same data item is the reciprocal of the first data item; if not, the first data item is shifted to obtain the second data item that can be found in the storage table, and according to the second data item The data item determines the inverse of the first data item.
[0092] Operation unit 4, used to combine. The reciprocal of the first data item is multiplied by the data item used as the dividend in the division operation to complete the division operation.
[0093] Among them, storage unit 1 is specifically used for:
[0094] Will 2 i To 2 i+1 The reciprocal of an integer between -1 is used as the reciprocal of the setting data item in the storage table, and is stored in the storage table, where i is the corresponding power value when the storage data item is determined in the storage table, and the value of i is i=0, 1, 2, 3,..., 32.
[0095] Preferably, the storage unit 1 is specifically used for:
[0096] Will 2 5 To 2 6 The reciprocal of an integer between -1 is stored in the storage table as the reciprocal of the setting data item in the storage table.
[0097] Further, the reciprocal determination unit 3 is specifically used for:
[0098] Binary conversion of the first data item to obtain the first data item expressed in binary;
[0099] Using the formula X=[log 2 M]-i, determine the number of bits to be shifted, where M is the first data item, X is the number of bits to be shifted, and the symbol [] means rounding down;
[0100] The first data item expressed in binary is shifted forward by X bits to obtain the second data item.
[0101] Further, the reciprocal determination unit 3 is specifically used for:
[0102] Reversely shift the reciprocal of the second data item stored in the storage table by X bits to obtain the reference value of the reciprocal of the first data item;
[0103] Use ((a[N+1]-a[N])*(M-(N<>(X*2) to perform linear interpolation to obtain the correction value of the reciprocal of the first data item, where a[N] is the reciprocal of the second data item, a[N+1] is the reciprocal of the data item adjacent to the second data item, M is the first data item, (N<>(X*2) means that it is shifted by 2X bits in the forward direction, and X is the number of bits of the shift;
[0104] The sum of the reference value and the correction value is used as the reciprocal of the first data item.
[0105] The device for division operation based on FPGA provided in the embodiment of the present invention stores the reciprocal of preset data items in the storage table without storing all data items, reducing resource consumption, and when performing division operations, it is judged as the divisor when performing division operations. If the first data item is in the preset storage table, if yes, directly call the reciprocal of the data item stored in the storage table, if not, use the shift operation method to determine the second data item in the storage table, and pass the first The two data items determine the reciprocal of the first data item as the divisor, which expands the numerical range of division operations in FPGA.
[0106] In the embodiment of the present invention, the above-mentioned FPGA-based division operation device may be an independent component or integrated into other components.
[0107] It should be noted that the functional implementation and interaction modes of each module/unit in the FPGA-based division operation device in the embodiment of the present invention can further refer to the description of the relevant method embodiment.
[0108] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. In this way, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention is also intended to include these modifications and variations.