I would like A(I:I) to be recognized as being a single character. The statement: A(I:I)=B(J:J) is expanded to a full _s_cpy call for each character, whereas: A(1:1)=B(2:2) is recognised as a single character assignment. Currently I overcome the problem with a call to: SUBROUTINE CHRCPY(A,B) CHARACTER A,B A=B END ... CALL CHRCPY(A(I:I),B(J:J)) At -O3 this gets inlined as a single character assignment, which is what I want. This is not intuitive and only works within a program unit. Similarly: A(I:I).EQ.B(J:J) gets expanded to a call to _s_cmp for each character. This can be overcome with: ICHAR(A(I:I)).EQ.ICHAR(B(J:J)) Environment: System: SunOS daedelus 5.9 Generic_112233-05 sun4u sparc SUNW,Ultra-Enterprise Architecture: sun4 cygwin and Solaris host: sparc-sun-solaris2.9 build: sparc-sun-solaris2.9 target: sparc-sun-solaris2.9 configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls How-To-Repeat: PROGRAM test CHARACTER*26 A,B DATA A/'abcdefghijklmnopqrstuvwxyz'/ DO I=1,26 B(I:I)=CHAR(ICHAR(A(I:I))+ICHAR('A')-ICHAR('a')) END DO END
Fix: CALL CHRCPY(B(I:I),CHAR(ICHAR(A(I:I)+ICHAR('A')-ICHAR('a'))) and compile with -finline-functions For comparisons use: ICHAR(A(I:I)).EQ.ICHAR(B(I:I)) ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Is this a performance issue or a "correctness" issue ?
Subject: Re: please recognize Fortran STRING(K:K) as single Thanks for getting back to me, This is a performance issue. Changing a character in a FORTRAN string currently requires a call to _s_cpy. (Whereas changing a character in an array does not.) I am looking for similar compiled code for: CHARACTER A(6) DO I=1,6 A(I)=CHAR(I) ENDDO and: CHARACTER A*6 DO I=1,6 A(I:I)=CHAR(I) ENDDO Apart from being orders of magnitude slower, this is not a bug. I tried to log this with the lowest of priorities. Regards, Andy Robb. >>> "bdavis9659 at comcast dot net" <gcc-bugzilla@gcc.gnu.org> 30/09/03 13:46:52 >>> PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12456 ------- Additional Comments From bdavis9659 at comcast dot net 2003-09-30 12:46 ------- Is this a performance issue or a "correctness" issue ? ------- You are receiving this mail because: ------- You reported the bug, or are watching the reporter. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
This is most likely will not be done before the Fortran 95 compiler comes in, which is scheduled for 3.5 (some time in 2004).
... to mark as duplicate of 11522 *** This bug has been marked as a duplicate of 11522 ***
Sorry, operator error. Toon Moene
I recognize that A(I:I).EQ.B(J:J) is a GNU extension that means something like A(I:I).LEQ.B(J:J) and that ICHAR(A(I:I)).EQ.ICHAR(B(J:J)) is an ansi way to do it. This still leaves the problem of A(I:I)='C' calling _s_cpy
This also happens on the tree-ssa branch with f95: _gfortran_copy_string (1, &b[i], 1, &char.2);
The fix needs to check if len1 and len2 are constant and equal to one in gfc_conv_statement_function around line 1200 in trans-expr.c.
This will improve 168.wupwise at lease 1%. And I have partially fixed. Patches are coming soon.
This will also improve LAPACK too. As what shows up there is: CHARACTER a LOGICAL b a = 'a'
Subject: Bug 12456 Author: fengwang Date: Mon Jan 9 02:27:45 2006 New Revision: 109489 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109489 Log: fortran ChangeLog entry: 2006-01-09 Feng Wang <fengwang@nudt.edu.cn> PR fortran/12456 * trans-expr.c (gfc_to_single_character): New function that converts string to single character if its length is 1. (gfc_build_compare_string):New function that compare string and handle single character specially. (gfc_conv_expr_op): Use gfc_build_compare_string. (gfc_trans_string_copy): Use gfc_to_single_character. * trans-intrinsic.c (gfc_conv_intrinsic_strcmp): Use gfc_build_compare_string. * trans.h (gfc_build_compare_string): Add prototype. testsuite ChangeLog entry: 2006-01-09 Feng Wang <fengwang@nudt.edu.cn> PR fortran/12456 * gfortran.dg/single_char_string.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/single_char_string.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-expr.c trunk/gcc/fortran/trans-intrinsic.c trunk/gcc/fortran/trans.h trunk/gcc/testsuite/ChangeLog
Subject: Bug 12456 Author: fengwang Date: Mon Jan 9 02:54:25 2006 New Revision: 109491 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109491 Log: fortran 2006-01-09 Feng Wang <fengwang@nudt.edu.cn> PR fortran/12456 * trans-expr.c (gfc_to_single_character): New function that converts string to single character if its length is 1. (gfc_build_compare_string):New function that compare string and handle single character specially. (gfc_conv_expr_op): Use gfc_build_compare_string. (gfc_trans_string_copy): Use gfc_to_single_character. * trans-intrinsic.c (gfc_conv_intrinsic_strcmp): Use gfc_build_compare_string. * trans.h (gfc_build_compare_string): Add prototype. 2006-01-09 Feng Wang <fengwang@nudt.edu.cn> * simplify.c (gfc_simplify_char): Use UCHAR_MAX instead of literal constant. (gfc_simplify_ichar): Get the result from unsinged char and in the range 0 to UCHAR_MAX instead of CHAR_MIN to CHAR_MAX. testsuite 2006-01-09 Feng Wang <fengwang@nudt.edu.cn> PR fortran/12456 * gfortran.dg/single_char_string.f90: New test. 2006-01-09 Feng Wang <fengwang@nudt.edu.cn> * gfortran.dg/ichar2.f90: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/ichar_2.f90 branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/single_char_string.f90 Modified: branches/gcc-4_1-branch/gcc/fortran/ChangeLog branches/gcc-4_1-branch/gcc/fortran/simplify.c branches/gcc-4_1-branch/gcc/fortran/trans-expr.c branches/gcc-4_1-branch/gcc/fortran/trans-intrinsic.c branches/gcc-4_1-branch/gcc/fortran/trans.h branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Fixed.