Skip to contentSkip to conversation

target-arm: Add support for AArch32 ARMv8 CRC32 instructions

PATCH In review Will Newton 2 participants 4 messages Feb 26, 2014

lore
Share & tools
lore
#0 lore raw

v4 cover target-arm: Add support for AArch32 ARMv8 CRC32 instructions

This series adds support for the AArch32 CRC32 instructions added in ARMv8.

Will Newton (2):
include/qemu/crc32c.h: Rename include guards to match filename
target-arm: Add support for AArch32 ARMv8 CRC32 instructions

 configure              |  2 +-
 include/qemu/crc32c.h  |  4 ++--
 target-arm/cpu.c       |  1 +
 target-arm/cpu.h       |  1 +
 target-arm/helper.c    | 39 +++++++++++++++++++++++++++++++++++
 target-arm/helper.h    |  3 +++
 target-arm/translate.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 103 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v4 1/2 include/qemu/crc32c.h: Rename include guards to match filename

---
 include/qemu/crc32c.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Changes in v4:
- None

include/qemu/crc32c.h +2 -2
index 56d1c3b..dafb6a1 100644
@@ -25,8 +25,8 @@
  *
  */
 
-#ifndef QEMU_CRC32_H
-#define QEMU_CRC32_H
+#ifndef QEMU_CRC32C_H
+#define QEMU_CRC32C_H
 
 #include "qemu-common.h"
 
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v4 2/2 target-arm: Add support for AArch32 ARMv8 CRC32 instructions

In reply to Will Newton

Add support for AArch32 CRC32 and CRC32C instructions added in ARMv8 and add a CPU feature flag to enable these instructions.

The CRC32-C implementation used is the built-in qemu implementation and The CRC-32 implementation is from zlib. This requires adding zlib to LIBS to ensure it is linked for the linux-user binary.

---
 configure              |  2 +-
 target-arm/cpu.c       |  1 +
 target-arm/cpu.h       |  1 +
 target-arm/helper.c    | 39 +++++++++++++++++++++++++++++++++++
 target-arm/helper.h    |  3 +++
 target-arm/translate.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 101 insertions(+), 1 deletion(-)

Changes in v4:
- Add feature flag for CRC instructions
- Check for SBZ bits in ARM encoding
- Use more accurate flags for the helper definition

configure +1 -1
index 423f435..030da86 100755
@@ -1657,7 +1657,7 @@ EOF
             "Make sure to have the zlib libs and headers installed."
     fi
 fi
-libs_softmmu="$libs_softmmu -lz"
+LIBS="$LIBS -lz"
 
 ##########################################
 # libseccomp check
target-arm/cpu.c +1 -0
index 6e7ce89..8231e57 100644
@@ -922,6 +922,7 @@ static void arm_any_initfn(Object *obj)
     set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
     set_feature(&cpu->env, ARM_FEATURE_ARM_DIV);
     set_feature(&cpu->env, ARM_FEATURE_V7MP);
+    set_feature(&cpu->env, ARM_FEATURE_CRC);
 #ifdef TARGET_AARCH64
     set_feature(&cpu->env, ARM_FEATURE_AARCH64);
 #endif
target-arm/cpu.h +1 -0
index 3c8a2db..c3aeb74 100644
@@ -615,6 +615,7 @@ enum arm_features {
     ARM_FEATURE_AARCH64, /* supports 64 bit mode */
     ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */
     ARM_FEATURE_CBAR, /* has cp15 CBAR */
+    ARM_FEATURE_CRC, /* ARMv8 CRC instructions */
 };
 
 static inline int arm_feature(CPUARMState *env, int feature)
target-arm/helper.c +39 -0
index 1b111b6..5e4f0fa 100644
@@ -5,6 +5,8 @@
 #include "sysemu/arch_init.h"
 #include "sysemu/sysemu.h"
 #include "qemu/bitops.h"
+#include "qemu/crc32c.h"
+#include <zlib.h> /* For crc32 */
 
 #ifndef CONFIG_USER_ONLY
 static inline int get_phys_addr(CPUARMState *env, uint32_t address,
@@ -4392,3 +4394,40 @@ int arm_rmode_to_sf(int rmode)
     }
     return rmode;
 }
+
+static void crc_init_buffer(uint8_t *buf, uint32_t val, uint32_t bytes)
+{
+    memset(buf, 0, 4);
+
+    if (bytes == 1) {
+        buf[0] = val & 0xff;
+    } else if (bytes == 2) {
+        buf[0] = val & 0xff;
+        buf[1] = (val >> 8) & 0xff;
+    } else {
+        buf[0] = val & 0xff;
+        buf[1] = (val >> 8) & 0xff;
+        buf[2] = (val >> 16) & 0xff;
+        buf[3] = (val >> 24) & 0xff;
+    }
+}
+
+uint32_t HELPER(crc32)(uint32_t acc, uint32_t val, uint32_t bytes)
+{
+    uint8_t buf[4];
+
+    crc_init_buffer(buf, val, bytes);
+
+    /* zlib crc32 converts the accumulator and output to one's complement.  */
+    return crc32(acc ^ 0xffffffff, buf, bytes) ^ 0xffffffff;
+}
+
+uint32_t HELPER(crc32c)(uint32_t acc, uint32_t val, uint32_t bytes)
+{
+    uint8_t buf[4];
+
+    crc_init_buffer(buf, val, bytes);
+
+    /* Linux crc32c converts the output to one's complement.  */
+    return crc32c(acc, buf, bytes) ^ 0xffffffff;
+}
target-arm/helper.h +3 -0
index 19bd620..9738e49 100644
@@ -497,6 +497,9 @@ DEF_HELPER_3(neon_qzip32, void, env, i32, i32)
 DEF_HELPER_4(crypto_aese, void, env, i32, i32, i32)
 DEF_HELPER_4(crypto_aesmc, void, env, i32, i32, i32)
 
+DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)
+DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)
+
 #ifdef TARGET_AARCH64
 #include "helper-a64.h"
 #endif
target-arm/translate.c +56 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.1.4
Reviewed-by on the v4 series
#3 lore raw
In reply to Will Newton
Quoted 6 lines · Will Newton

This series adds support for the AArch32 CRC32 instructions added in ARMv8.

Will Newton (2):
include/qemu/crc32c.h: Rename include guards to match filename
target-arm: Add support for AArch32 ARMv8 CRC32 instructions

Thanks
-- PMM