[patch, libgfortran] PR48552/48925 Invalid spaces in complex/code cleanup

Jerry DeLisle jvdelisle@charter.net
Sat Jun 18 19:24:00 GMT 2016


Greetings all,

This is a major rework of floating point write routines. Most of the existing
critical code is retained. Much of the code is reorganized.

The problem with complex is that it is writing two floats with formatting.
Previously write_block, which does the actual output, was buried at the bottom
of all the functions. We do not know how wide the significant result is until
that point. These means we had no way to calculate how many blanks to transmit
first to right justify until we already sent the digits.

This patch modifies this by 1) moving the buffer creations up to the higher
routines, 2) formatting a string, 3) getting the final lengths, and 4)
calculating the leading blanks needed. Once this is determined, the complex
value can sent out correctly.

Several helper functions are created. The most significant is probably
write_float_string. It takes a simple string from all the other lower level
routines, and uses write_block. All the previous kind=4 character internal  unit
code spread throughout the previous output_float routines is now done with about
5 lines of code.

Regression tested on x86_64. Test cases modified for the new format of default
complex.
(changelog for test cases will be done of course)

OK for trunk?

Regards,

Jerry

2016-06-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/48852
	* io/write.c: Cleaned up whitespace.
	(write_d, write_e, write_f, write_es, write_en): Use new helper function
	write_float_0. (write_float_0): New helper function.
	(get_precision, select_buffer, select_string, write_float_string): New
	helper functions used in remaining float writing functions. Helper function
	write_float_string now contains code for writing to kind=4 character
	internal units.
	(write_real): Modified to establish working buffers at this level and to
	use new helper functions.
	(write_real_g0): Likewise modified.
	(write_complex): Likewise modified. Gets both float strings before
	output so that final lengths can be determined which allows right
	justifying the complex number with no intervening spaces.
	* io/write_float.def (build_float_string): Renamed from previously
	output_float, modified to use buffers passed in from higher functions,
	builds a null terminated string of the floating point value. Character
	kind=4 code eliminated.
	(write_infnan): Likewise modified to use incoming buffers and eliminate
	kind=4 related code.
	(OUTPUT_FLOAT_FMT_G): Deleted. Functionality moved into FORMAT_FLOAT.
	(FORMAT_FLOAT): Renamed macro from WRITE_FLOAT. Use build_float_string.
	(get_float_string): Renamed from write_float, uses FORMAT_FLOAT macro.
	Buffer allocation removed, now at higher level.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: submit.diff
Type: text/x-patch
Size: 35335 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160618/4a08142b/attachment.bin>


More information about the Gcc-patches mailing list