[PATCH] D156814: [NFC] Refactor byteswapped writes

Chris Bieneman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 11:02:47 PDT 2023


beanz updated this revision to Diff 546152.
beanz added a comment.

Updating to use support::endian::write. Thank you @efriedma!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156814/new/

https://reviews.llvm.org/D156814

Files:
  llvm/lib/MC/DXContainerPSVInfo.cpp


Index: llvm/lib/MC/DXContainerPSVInfo.cpp
===================================================================
--- llvm/lib/MC/DXContainerPSVInfo.cpp
+++ llvm/lib/MC/DXContainerPSVInfo.cpp
@@ -8,6 +8,7 @@
 
 #include "llvm/MC/DXContainerPSVInfo.h"
 #include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/Support/EndianStream.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
@@ -31,24 +32,16 @@
     InfoSize = sizeof(dxbc::PSV::v2::RuntimeInfo);
     BindingSize = sizeof(dxbc::PSV::v2::ResourceBindInfo);
   }
-  uint32_t InfoSizeSwapped = InfoSize;
-  if (sys::IsBigEndianHost)
-    sys::swapByteOrder(InfoSizeSwapped);
   // Write the size of the info.
-  OS.write(reinterpret_cast<const char *>(&InfoSizeSwapped), sizeof(uint32_t));
+
+  support::endian::write(OS, InfoSize, support::little);
   // Write the info itself.
   OS.write(reinterpret_cast<const char *>(&BaseData), InfoSize);
 
   uint32_t ResourceCount = static_cast<uint32_t>(Resources.size());
-  uint32_t BindingSizeSwapped = BindingSize;
-  if (sys::IsBigEndianHost) {
-    sys::swapByteOrder(ResourceCount);
-    sys::swapByteOrder(BindingSizeSwapped);
-  }
 
-  OS.write(reinterpret_cast<const char *>(&ResourceCount), sizeof(uint32_t));
-  OS.write(reinterpret_cast<const char *>(&BindingSizeSwapped),
-           sizeof(uint32_t));
+  support::endian::write(OS, ResourceCount, support::little);
+  support::endian::write(OS, BindingSize, support::little);
 
   for (const auto &Res : Resources)
     OS.write(reinterpret_cast<const char *>(&Res), BindingSize);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156814.546152.patch
Type: text/x-patch
Size: 1557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230801/7a9fc90e/attachment.bin>


More information about the llvm-commits mailing list