From 607eccfa2d6c8fcd702f0830cb86b2a84c73430f Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Sat, 13 Jun 2026 17:26:46 +0200 Subject: [PATCH] lsame: simplify using IACHAR Replace ICHAR with the F95 intrinsic IACHAR, which always returns ASCII codes regardless of the platform's native character encoding. This eliminates the entire EBCDIC/Prime machine detection branch (logic testing ZCODE against ASCII/EBCDIC/Prime codes), producing shorter, simpler, and equivalent code. Closes #701 --- BLAS/SRC/lsame.f | 51 ++++++++---------------------------------------- INSTALL/lsame.f | 51 ++++++++---------------------------------------- 2 files changed, 16 insertions(+), 86 deletions(-) diff --git a/BLAS/SRC/lsame.f b/BLAS/SRC/lsame.f index 10246991e..8da0df82e 100644 --- a/BLAS/SRC/lsame.f +++ b/BLAS/SRC/lsame.f @@ -63,57 +63,22 @@ LOGICAL FUNCTION LSAME(CA,CB) * ===================================================================== * * .. Intrinsic Functions .. - INTRINSIC ICHAR + INTRINSIC IACHAR * .. * .. Local Scalars .. - INTEGER INTA,INTB,ZCODE + INTEGER INTA,INTB * .. -* -* Test if the characters are equal * LSAME = CA .EQ. CB IF (LSAME) RETURN * -* Now test for equivalence if both characters are alphabetic. -* - ZCODE = ICHAR('Z') -* -* Use 'Z' rather than 'A' so that ASCII can be detected on Prime -* machines, on which ICHAR returns a value with bit 8 set. -* ICHAR('A') on Prime machines returns 193 which is the same as -* ICHAR('A') on an EBCDIC machine. -* - INTA = ICHAR(CA) - INTB = ICHAR(CB) -* - IF (ZCODE.EQ.90 .OR. ZCODE.EQ.122) THEN -* -* ASCII is assumed - ZCODE is the ASCII code of either lower or -* upper case 'Z'. -* - IF (INTA.GE.97 .AND. INTA.LE.122) INTA = INTA - 32 - IF (INTB.GE.97 .AND. INTB.LE.122) INTB = INTB - 32 -* - ELSE IF (ZCODE.EQ.233 .OR. ZCODE.EQ.169) THEN -* -* EBCDIC is assumed - ZCODE is the EBCDIC code of either lower or -* upper case 'Z'. -* - IF (INTA.GE.129 .AND. INTA.LE.137 .OR. - + INTA.GE.145 .AND. INTA.LE.153 .OR. - + INTA.GE.162 .AND. INTA.LE.169) INTA = INTA + 64 - IF (INTB.GE.129 .AND. INTB.LE.137 .OR. - + INTB.GE.145 .AND. INTB.LE.153 .OR. - + INTB.GE.162 .AND. INTB.LE.169) INTB = INTB + 64 -* - ELSE IF (ZCODE.EQ.218 .OR. ZCODE.EQ.250) THEN -* -* ASCII is assumed, on Prime machines - ZCODE is the ASCII code -* plus 128 of either lower or upper case 'Z'. +* Use IACHAR to get ASCII codes for case-insensitive comparison, +* regardless of the platform's native character encoding. * - IF (INTA.GE.225 .AND. INTA.LE.250) INTA = INTA - 32 - IF (INTB.GE.225 .AND. INTB.LE.250) INTB = INTB - 32 - END IF + INTA = IACHAR(CA) + INTB = IACHAR(CB) + IF (INTA.GE.65 .AND. INTA.LE.90) INTA = INTA + 32 + IF (INTB.GE.65 .AND. INTB.LE.90) INTB = INTB + 32 LSAME = INTA .EQ. INTB * * RETURN diff --git a/INSTALL/lsame.f b/INSTALL/lsame.f index 5ed6adb45..2ffb7e0d8 100644 --- a/INSTALL/lsame.f +++ b/INSTALL/lsame.f @@ -58,59 +58,24 @@ LOGICAL FUNCTION LSAME( CA, CB ) * ===================================================================== * * .. Intrinsic Functions .. - INTRINSIC ICHAR + INTRINSIC IACHAR * .. * .. Local Scalars .. - INTEGER INTA, INTB, ZCODE + INTEGER INTA, INTB * .. * .. Executable Statements .. -* -* Test if the characters are equal * LSAME = CA.EQ.CB IF( LSAME ) $ RETURN * -* Now test for equivalence if both characters are alphabetic. -* - ZCODE = ICHAR( 'Z' ) -* -* Use 'Z' rather than 'A' so that ASCII can be detected on Prime -* machines, on which ICHAR returns a value with bit 8 set. -* ICHAR('A') on Prime machines returns 193 which is the same as -* ICHAR('A') on an EBCDIC machine. -* - INTA = ICHAR( CA ) - INTB = ICHAR( CB ) -* - IF( ZCODE.EQ.90 .OR. ZCODE.EQ.122 ) THEN -* -* ASCII is assumed - ZCODE is the ASCII code of either lower or -* upper case 'Z'. -* - IF( INTA.GE.97 .AND. INTA.LE.122 ) INTA = INTA - 32 - IF( INTB.GE.97 .AND. INTB.LE.122 ) INTB = INTB - 32 -* - ELSE IF( ZCODE.EQ.233 .OR. ZCODE.EQ.169 ) THEN -* -* EBCDIC is assumed - ZCODE is the EBCDIC code of either lower or -* upper case 'Z'. -* - IF( INTA.GE.129 .AND. INTA.LE.137 .OR. - $ INTA.GE.145 .AND. INTA.LE.153 .OR. - $ INTA.GE.162 .AND. INTA.LE.169 ) INTA = INTA + 64 - IF( INTB.GE.129 .AND. INTB.LE.137 .OR. - $ INTB.GE.145 .AND. INTB.LE.153 .OR. - $ INTB.GE.162 .AND. INTB.LE.169 ) INTB = INTB + 64 -* - ELSE IF( ZCODE.EQ.218 .OR. ZCODE.EQ.250 ) THEN -* -* ASCII is assumed, on Prime machines - ZCODE is the ASCII code -* plus 128 of either lower or upper case 'Z'. +* Use IACHAR to get ASCII codes for case-insensitive comparison, +* regardless of the platform's native character encoding. * - IF( INTA.GE.225 .AND. INTA.LE.250 ) INTA = INTA - 32 - IF( INTB.GE.225 .AND. INTB.LE.250 ) INTB = INTB - 32 - END IF + INTA = IACHAR( CA ) + INTB = IACHAR( CB ) + IF( INTA.GE.65 .AND. INTA.LE.90 ) INTA = INTA + 32 + IF( INTB.GE.65 .AND. INTB.LE.90 ) INTB = INTB + 32 LSAME = INTA.EQ.INTB * * RETURN