[PATCH] D144506: [libc] Implement ntohl and ntohs

Raman Tenneti via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 22 10:09:11 PST 2023


rtenneti updated this revision to Diff 499572.
rtenneti added a comment.

Dif a git pull --rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144506

Files:
  libc/src/network/ntohl.cpp
  libc/src/network/ntohs.cpp


Index: libc/src/network/ntohs.cpp
===================================================================
--- libc/src/network/ntohs.cpp
+++ libc/src/network/ntohs.cpp
@@ -13,7 +13,10 @@
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(uint16_t, ntohs, (uint16_t netshort)) {
-  return Endian::IS_LITTLE ? __builtin_bswap16(netshort) : netshort;
+  if constexpr (Endian::IS_LITTLE)
+    return __builtin_bswap16(netshort);
+  else
+    return netshort;
 }
 
 } // namespace __llvm_libc
Index: libc/src/network/ntohl.cpp
===================================================================
--- libc/src/network/ntohl.cpp
+++ libc/src/network/ntohl.cpp
@@ -13,7 +13,10 @@
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(uint32_t, ntohl, (uint32_t netlong)) {
-  return Endian::IS_LITTLE ? __builtin_bswap32(netlong) : netlong;
+  if constexpr (Endian::IS_LITTLE)
+    return __builtin_bswap32(netlong);
+  else
+    return netlong;
 }
 
 } // namespace __llvm_libc


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144506.499572.patch
Type: text/x-patch
Size: 955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230222/9150fd37/attachment.bin>


More information about the llvm-commits mailing list