Skip to contentSkip to conversation

loongarch/crypto: Clean up useless assignment operations

PATCH Superseded WangYuli 5 participants 9 messages Feb 26, 2024 – Feb 29, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

WangYuli

author
#0 lore raw

PATCH 1/1 loongarch/crypto: Clean up useless assignment operations

Both crc32 and crc32c hw accelerated funcs will calculate the remaining len. Those codes are derived from arch/mips/crypto/crc32-mips.c and "len -= sizeof(u32)" is not necessary for 64-bit CPUs.

Removing it can make context code style more unified and improve code readability.

---
 arch/loongarch/crypto/crc32-loongarch.c | 2 --
 1 file changed, 2 deletions(-)
arch/loongarch/crypto/crc32-loongarch.c +0 -2
index a49e507af38c..3eebea3a7b47 100644
@@ -44,7 +44,6 @@ static u32 crc32_loongarch_hw(u32 crc_, const u8 *p, unsigned int len)
 
 		CRC32(crc, value, w);
 		p += sizeof(u32);
-		len -= sizeof(u32);
 	}
 
 	if (len & sizeof(u16)) {
@@ -80,7 +79,6 @@ static u32 crc32c_loongarch_hw(u32 crc_, const u8 *p, unsigned int len)
 
 		CRC32C(crc, value, w);
 		p += sizeof(u32);
-		len -= sizeof(u32);
 	}
 
 	if (len & sizeof(u16)) {
Signature · 1 line
2.33.1
reviewer
#1 lore raw
Quoted 27 lines · WangYuli

Both crc32 and crc32c hw accelerated funcs will calculate the remaining len. Those codes are derived from arch/mips/crypto/crc32-mips.c and "len -= sizeof(u32)" is not necessary for 64-bit CPUs.

Removing it can make context code style more unified and improve code readability.

---
  arch/loongarch/crypto/crc32-loongarch.c | 2 --
  1 file changed, 2 deletions(-)
arch/loongarch/crypto/crc32-loongarch.c +0 -1
index a49e507af38c..3eebea3a7b47 100644
@@ -44,7 +44,6 @@ static u32 crc32_loongarch_hw(u32 crc_, const u8 *p, unsigned int len)
 
  		CRC32(crc, value, w);
  		p += sizeof(u32);
-		len -= sizeof(u32);
  	}
 
  	if (len & sizeof(u16)) {

arch/loongarch/crypto/crc32-loongarch.c static u32 crc32c_loongarch_hw(u32 crc_, const u8 *p, unsigned int len) · line 84

Quoted 7 lines
arch/loongarch/crypto/crc32-loongarch.c +0 -1
@@ -80,7 +79,6 @@ static u32 crc32c_loongarch_hw(u32 crc_, const u8 *p, unsigned int len)
 
  		CRC32C(crc, value, w);
  		p += sizeof(u32);
-		len -= sizeof(u32);
  	}
 
  	if (len & sizeof(u16)) {

Sure, but IIRC Loongson still has hopes in having 32-bit-only models support upstream? The possibility cannot be ruled out because from public information (e.g. the 2023-11-28 news event), Loongson is known to be actively licensing their reduced 32-bit-only IP cores to third parties.

Ultimately whether we want to imply 64-bit operation with the crc32 module is up to Loongson to decide, and I think Huacai may have something to add, but IMO at least we could gate the statement with #ifdef's so we don't outright lose 32-bit compatibility with this code.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#2 lore raw

Sure,but we not seem to have "crc.w.d.w" dword asm in loongarch 32bit mode,now the whole file can only run in 64bit mode?

Thanks.

reviewer
#3 lore raw
Quoted 3 lines · 关文涛

Sure,but we not seem to have "crc.w.d.w" dword asm in loongarch 32bit mode,now the whole file can only run in 64bit mode?

Thanks.

Sorry. I have checked the manual and it turns out you & Yuli are correct: even though the narrower CRC instructions doesn't require GRLEN=64, they still *aren't* part of LA32 (LoongArch reference manual v1.10, Volume 1, Table 2-1). Counter-intuitive as it is, the original patch is correct nevertheless.

I'm going to amend my review shortly.

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#4 lore raw
Quoted 5 lines · WANG Xuerui

Sorry. I have checked the manual and it turns out you & Yuli are
correct: even though the narrower CRC instructions doesn't require GRLEN=64, they still *aren't* part of LA32 (LoongArch reference manual v1.10, Volume 1, Table 2-1). Counter-intuitive as it is, the original patch is correct nevertheless.

But I don't think the table in the spec will 100% reflect the real status of the LA32 hardware. And we should use CPUCFG to detect it anyway.

Based on my experience programming some aeronautic device I'd say having some hardware CRC support should be useful even in embedded area.

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
reviewer Reviewed-by
#5 lore raw
In reply to WANG Xuerui
Quoted 5 lines · WANG Xuerui
Quoted 4 lines · WangYuli

Both crc32 and crc32c hw accelerated funcs will calculate the remaining len. Those codes are derived from arch/mips/crypto/crc32-mips.c and "len -= sizeof(u32)" is not necessary for 64-bit CPUs.

It's ultimately unrelated to the width of the running CPU, but rather the LoongArch ISA specification. You should mention that because the LoongArch ISA manual implies that CRC instructions are only available on LA64-compatible implementations, the code can assume 64-bit operation, so the 32-bit codepath can be guaranteed to execute only once.

Quoted 3 lines
Quoted 3 lines

Removing it can make context code style more unified and improve code readability.

"Remove it to improve readability." should do it?

Quoted 28 lines
Quoted 19 lines

---
  arch/loongarch/crypto/crc32-loongarch.c | 2 --

  1 file changed, 2 deletions(-)
arch/loongarch/crypto/crc32-loongarch.c +0 -1
index a49e507af38c..3eebea3a7b47 100644
@@ -44,7 +44,6 @@ static u32 crc32_loongarch_hw(u32 crc_, const u8 *p, 
 unsigned int len)
           CRC32(crc, value, w);
           p += sizeof(u32);
-        len -= sizeof(u32);
       }
       if (len & sizeof(u16)) {

arch/loongarch/crypto/crc32-loongarch.c static u32 crc32c_loongarch_hw(u32 crc_, const u8 · line 83

Quoted 6 lines
arch/loongarch/crypto/crc32-loongarch.c +0 -1
@@ -80,7 +79,6 @@ static u32 crc32c_loongarch_hw(u32 crc_, const u8 
 *p, unsigned int len)
           CRC32C(crc, value, w);
           p += sizeof(u32);
-        len -= sizeof(u32);
       }
       if (len & sizeof(u16)) {

Sure, but IIRC Loongson still has hopes in having 32-bit-only models support upstream? The possibility cannot be ruled out because from public information (e.g. the 2023-11-28 news event), Loongson is known to be actively licensing their reduced 32-bit-only IP cores to third parties.

Quoted 2 lines

Ultimately whether we want to imply 64-bit operation with the crc32 module is up to Loongson to decide, and I think Huacai may have something to add, but IMO at least we could gate the statement with #ifdef's so we don't outright lose 32-bit compatibility with this code.

I was wrong in assuming that LA32 must contain CRC insns that operate on at most 32 bits. In fact this is wrong -- the LA32 subset omits a lot of 32-bit operations for no apparent reason (perhaps implementation simplicity but outsiders cannot confirm). So by definition the code cannot be ported to LA32, and the changes are correct.

But for the same reason, the commit message is misleading. See above. And with the nits addressed:

Signature · 3 lines
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
#6 lore raw

Okay, somehow i think Yuli the origin commit message some misleading things,the whole story expand that origin mips/crypto/crc32-mips.c code "len -= sizeof(u32);" necessary only in "!CONFIG_64BIT" macro define, they are just a "binary bit" game as we tran the number to binary bit, while less and less one in 64bit ,the less thing we do if >=32bit do once,

Quoted 1 line

=16bit do once ... etc... If we delete the useless code line, it is very cool,

and unrelated to specific ISA. We also think maybe we need to add "#ifnef CONFIG_64BIT"in origin mips/crypto/crc32-mips.c "len -= sizeof(u32);", but it add code instead of delete code...

Thanks.
Guan Wentao

author
#7 lore raw

That's why I didn't have sent a patch to MIPS group.

WangYuli

maintainer
#8 lore raw
In reply to WangYuli

Hi, Yuli,

The code is fine to me, please change loongarch to LoongArch in the subject, and update your commit message with Xuerui's review in V2.

Huacai

Quoted 38 lines · WangYuli

Both crc32 and crc32c hw accelerated funcs will calculate the remaining len. Those codes are derived from arch/mips/crypto/crc32-mips.c and "len -= sizeof(u32)" is not necessary for 64-bit CPUs.

Removing it can make context code style more unified and improve code readability.

---
 arch/loongarch/crypto/crc32-loongarch.c | 2 --
 1 file changed, 2 deletions(-)
arch/loongarch/crypto/crc32-loongarch.c +0 -3
index a49e507af38c..3eebea3a7b47 100644
@@ -44,7 +44,6 @@ static u32 crc32_loongarch_hw(u32 crc_, const u8 *p, unsigned int len)
 
                CRC32(crc, value, w);
                p += sizeof(u32);
-               len -= sizeof(u32);
        }
 
        if (len & sizeof(u16)) {
@@ -80,7 +79,6 @@ static u32 crc32c_loongarch_hw(u32 crc_, const u8 *p, unsigned int len)
 
                CRC32C(crc, value, w);
                p += sizeof(u32);
-               len -= sizeof(u32);
        }
 
        if (len & sizeof(u16)) {
--

2.33.1