[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] Use memcpy/byteswap to translate CDB words


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Tue, 28 Apr 2026 10:33:42 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
  • Cc: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>, Owen Smith <owen.smith@xxxxxxxxxx>
  • Delivery-date: Tue, 28 Apr 2026 08:34:16 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

MSVC cannot optimize manual byte concatenation.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 include/xencdb.h | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/xencdb.h b/include/xencdb.h
index 594e9fe..ae19f09 100644
--- a/include/xencdb.h
+++ b/include/xencdb.h
@@ -33,24 +33,31 @@
 #ifndef XENCDB_H
 #define XENCDB_H
 
+#include <intrin.h>
+
 #define XENCDB_SCSIOP_INVALID 0xFF
 
 FORCEINLINE USHORT Cdb_get_big_endian_word(const UCHAR src[2])
 {
-    return src[1] | ((USHORT)src[0] << 8);
+    USHORT      Result;
+
+    memcpy(&Result, src, 2);
+    return _byteswap_ushort(Result);
 }
 FORCEINLINE ULONG Cdb_get_big_endian_dword(const UCHAR src[4])
 {
-    return src[3] | ((ULONG)src[2] << 8) | ((ULONG)src[1] << 16) |
-            ((ULONG)src[0] << 24);
+    ULONG       Result;
+
+    memcpy(&Result, src, 4);
+    return _byteswap_ulong(Result);
 }
 
 FORCEINLINE ULONG64 Cdb_get_big_endian_qword(const UCHAR src[8])
 {
-    return src[7] | ((ULONG64)src[6] << 8) | ((ULONG64)src[5] << 16) |
-        ((ULONG64)src[4] << 24) | ((ULONG64)src[3] << 32) |
-        ((ULONG64)src[2] << 40) | ((ULONG64)src[1] << 48) |
-        ((ULONG64)src[0] << 56);
+    ULONG64     Result;
+
+    memcpy(&Result, src, 8);
+    return _byteswap_uint64(Result);
 }
 
 FORCEINLINE UCHAR Cdb_CheckLen6(UCHAR op)
-- 
2.53.0.windows.2



--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.