All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] vectorize is_dup_page
@ 2011-12-23 15:17 Paolo Bonzini
  2012-01-13 15:55 ` Paolo Bonzini
  2012-01-13 16:54 ` Anthony Liguori
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2011-12-23 15:17 UTC (permalink / raw)
  To: qemu-devel

is_dup_page is already proceeding in 32-bit chunks.  Changing it
to 16 bytes using Altivec or SSE is easy.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch_init.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index d4c92b0..8466ffb 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -94,14 +94,30 @@ const uint32_t arch_type = QEMU_ARCH;
 #define RAM_SAVE_FLAG_EOS      0x10
 #define RAM_SAVE_FLAG_CONTINUE 0x20
 
-static int is_dup_page(uint8_t *page, uint8_t ch)
+#ifdef __ALTIVEC__
+#include <altivec.h>
+#define VECTYPE        vector unsigned char
+#define SPLAT(p)       vec_splat(vec_ld(0, p), 0)
+#define ALL_EQ(v1, v2) vec_all_eq(v1, v2)
+#elif defined __SSE2__
+#include <emmintrin.h>
+#define VECTYPE        __m128i
+#define SPLAT(p)       _mm_set1_epi8(*(p))
+#define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF)
+#else
+#define VECTYPE        unsigned long
+#define SPLAT(p)       (*(p) * (~0UL / 255))
+#define ALL_EQ(v1, v2) ((v1) == (v2))
+#endif
+
+static int is_dup_page(uint8_t *page)
 {
-    uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
-    uint32_t *array = (uint32_t *)page;
+    VECTYPE *p = (VECTYPE *)page;
+    VECTYPE val = SPLAT(page);
     int i;
 
-    for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) {
-        if (array[i] != val) {
+    for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
+        if (!ALL_EQ(val, p[i])) {
             return 0;
         }
     }
@@ -135,7 +151,7 @@ static int ram_save_block(QEMUFile *f)
 
             p = block->host + offset;
 
-            if (is_dup_page(p, *p)) {
+            if (is_dup_page(p)) {
                 qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS);
                 if (!cont) {
                     qemu_put_byte(f, strlen(block->idstr));
-- 
1.7.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] vectorize is_dup_page
  2011-12-23 15:17 [Qemu-devel] [PATCH v2] vectorize is_dup_page Paolo Bonzini
@ 2012-01-13 15:55 ` Paolo Bonzini
  2012-01-13 16:54 ` Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2012-01-13 15:55 UTC (permalink / raw)
  To: qemu-devel

On 12/23/2011 04:17 PM, Paolo Bonzini wrote:
> is_dup_page is already proceeding in 32-bit chunks.  Changing it
> to 16 bytes using Altivec or SSE is easy.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
> ---
>   arch_init.c |   28 ++++++++++++++++++++++------
>   1 files changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/arch_init.c b/arch_init.c
> index d4c92b0..8466ffb 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -94,14 +94,30 @@ const uint32_t arch_type = QEMU_ARCH;
>   #define RAM_SAVE_FLAG_EOS      0x10
>   #define RAM_SAVE_FLAG_CONTINUE 0x20
>
> -static int is_dup_page(uint8_t *page, uint8_t ch)
> +#ifdef __ALTIVEC__
> +#include<altivec.h>
> +#define VECTYPE        vector unsigned char
> +#define SPLAT(p)       vec_splat(vec_ld(0, p), 0)
> +#define ALL_EQ(v1, v2) vec_all_eq(v1, v2)
> +#elif defined __SSE2__
> +#include<emmintrin.h>
> +#define VECTYPE        __m128i
> +#define SPLAT(p)       _mm_set1_epi8(*(p))
> +#define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF)
> +#else
> +#define VECTYPE        unsigned long
> +#define SPLAT(p)       (*(p) * (~0UL / 255))
> +#define ALL_EQ(v1, v2) ((v1) == (v2))
> +#endif
> +
> +static int is_dup_page(uint8_t *page)
>   {
> -    uint32_t val = ch<<  24 | ch<<  16 | ch<<  8 | ch;
> -    uint32_t *array = (uint32_t *)page;
> +    VECTYPE *p = (VECTYPE *)page;
> +    VECTYPE val = SPLAT(page);
>       int i;
>
> -    for (i = 0; i<  (TARGET_PAGE_SIZE / 4); i++) {
> -        if (array[i] != val) {
> +    for (i = 0; i<  TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
> +        if (!ALL_EQ(val, p[i])) {
>               return 0;
>           }
>       }
> @@ -135,7 +151,7 @@ static int ram_save_block(QEMUFile *f)
>
>               p = block->host + offset;
>
> -            if (is_dup_page(p, *p)) {
> +            if (is_dup_page(p)) {
>                   qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS);
>                   if (!cont) {
>                       qemu_put_byte(f, strlen(block->idstr));

Ping.

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] vectorize is_dup_page
  2011-12-23 15:17 [Qemu-devel] [PATCH v2] vectorize is_dup_page Paolo Bonzini
  2012-01-13 15:55 ` Paolo Bonzini
@ 2012-01-13 16:54 ` Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2012-01-13 16:54 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On 12/23/2011 09:17 AM, Paolo Bonzini wrote:
> is_dup_page is already proceeding in 32-bit chunks.  Changing it
> to 16 bytes using Altivec or SSE is easy.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>

Applied.  Thanks.

Regards,

Anthony Liguori

> ---
>   arch_init.c |   28 ++++++++++++++++++++++------
>   1 files changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/arch_init.c b/arch_init.c
> index d4c92b0..8466ffb 100644
> --- a/arch_init.c
> +++ b/arch_init.c
> @@ -94,14 +94,30 @@ const uint32_t arch_type = QEMU_ARCH;
>   #define RAM_SAVE_FLAG_EOS      0x10
>   #define RAM_SAVE_FLAG_CONTINUE 0x20
>
> -static int is_dup_page(uint8_t *page, uint8_t ch)
> +#ifdef __ALTIVEC__
> +#include<altivec.h>
> +#define VECTYPE        vector unsigned char
> +#define SPLAT(p)       vec_splat(vec_ld(0, p), 0)
> +#define ALL_EQ(v1, v2) vec_all_eq(v1, v2)
> +#elif defined __SSE2__
> +#include<emmintrin.h>
> +#define VECTYPE        __m128i
> +#define SPLAT(p)       _mm_set1_epi8(*(p))
> +#define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF)
> +#else
> +#define VECTYPE        unsigned long
> +#define SPLAT(p)       (*(p) * (~0UL / 255))
> +#define ALL_EQ(v1, v2) ((v1) == (v2))
> +#endif
> +
> +static int is_dup_page(uint8_t *page)
>   {
> -    uint32_t val = ch<<  24 | ch<<  16 | ch<<  8 | ch;
> -    uint32_t *array = (uint32_t *)page;
> +    VECTYPE *p = (VECTYPE *)page;
> +    VECTYPE val = SPLAT(page);
>       int i;
>
> -    for (i = 0; i<  (TARGET_PAGE_SIZE / 4); i++) {
> -        if (array[i] != val) {
> +    for (i = 0; i<  TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
> +        if (!ALL_EQ(val, p[i])) {
>               return 0;
>           }
>       }
> @@ -135,7 +151,7 @@ static int ram_save_block(QEMUFile *f)
>
>               p = block->host + offset;
>
> -            if (is_dup_page(p, *p)) {
> +            if (is_dup_page(p)) {
>                   qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS);
>                   if (!cont) {
>                       qemu_put_byte(f, strlen(block->idstr));

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-13 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-23 15:17 [Qemu-devel] [PATCH v2] vectorize is_dup_page Paolo Bonzini
2012-01-13 15:55 ` Paolo Bonzini
2012-01-13 16:54 ` Anthony Liguori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.