diff --git a/CMakeLists.txt b/CMakeLists.txt
index 23fbc571b1114d0517b6f1048b0cd7a52f327a2a..93705dd9a0dbe14bab70d0ae4be08ab2d2f66ee2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -142,6 +142,7 @@ check_include_file("string.h"      HAVE_STRING_H)
 check_include_file("unistd.h"      HAVE_UNISTD_H)
 check_include_file("sys/endian.h"  HAVE_SYS_ENDIAN_H)
 check_include_file("endian.h"      HAVE_ENDIAN_H)
+check_include_file("byteswap.h"    HAVE_BYTESWAP_H)
 
 include(CheckTypeSize)
 # Checks for typedefs, structures, and compiler characteristics.
@@ -161,6 +162,8 @@ if(HAVE_SYS_ENDIAN_H)
   check_symbol_exists(be64toh "sys/endian.h" HAVE_BE64TOH)
 endif()
 
+check_symbol_exists(bswap_64 "byteswap.h" HAVE_BSWAP_64)
+
 include(ExtractValidFlags)
 set(WARNCFLAGS)
 set(WARNCXXFLAGS)
diff --git a/configure.ac b/configure.ac
index 34924e67dc36fb11a953bae5d8ed784532a5ac3d..b645eab9ac36447d4a67397b073f0bc9afdd76f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -294,6 +294,7 @@ AC_CHECK_HEADERS([ \
   unistd.h \
   sys/endian.h \
   endian.h \
+  byteswap.h \
 ])
 
 # Checks for typedefs, structures, and compiler characteristics.
@@ -331,6 +332,10 @@ AC_CHECK_DECLS([be64toh], [], [], [[
 #endif
 ]])
 
+AC_CHECK_DECLS([bswap_64], [], [], [[
+#include <byteswap.h>
+]])
+
 # More compiler flags from nghttp2.
 save_CFLAGS=$CFLAGS
 save_CXXFLAGS=$CXXFLAGS
diff --git a/lib/ngtcp2_conv.h b/lib/ngtcp2_conv.h
index f3336f44a92dad46859be6e7e39b40277db2dda8..ebb264d03bbe0b5899b96412a6b3b2600f1764ad 100644
--- a/lib/ngtcp2_conv.h
+++ b/lib/ngtcp2_conv.h
@@ -37,6 +37,10 @@
 #  include <netinet/in.h>
 #endif /* HAVE_NETINET_IN_H */
 
+#ifdef HAVE_BYTESWAP_H
+#  include <byteswap.h>
+#endif /* HAVE_BYTESWAP_H */
+
 #ifdef HAVE_ENDIAN_H
 #  include <endian.h>
 #endif /* HAVE_ENDIAN_H */
@@ -47,16 +51,25 @@
 
 #include <ngtcp2/ngtcp2.h>
 
+#if defined HAVE_BSWAP_64 || HAVE_DECL_BSWAP_64
+#  define ngtcp2_bswap64 bswap_64
+#else /* !HAVE_BSWAP_64 */
+#  define ngtcp2_bswap64(N)                                                    \
+    ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
+#endif /* !HAVE_BSWAP_64 */
+
 #if defined HAVE_BE64TOH || HAVE_DECL_BE64TOH
 #  define ngtcp2_ntohl64(N) be64toh(N)
 #  define ngtcp2_htonl64(N) htobe64(N)
 #else /* !HAVE_BE64TOH */
-#  define ngtcp2_bswap64(N)                                                    \
-    ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
-#  define ngtcp2_ntohl64(N) ngtcp2_bswap64(N)
-#  define ngtcp2_htonl64(N) ngtcp2_bswap64(N)
-#endif /* !HAVE_BE64TOH */
-
+#  if defined WORDS_BIGENDIAN
+#    define ngtcp2_ntohl64(N) (N)
+#    define ngtcp2_htonl64(N) (N)
+#  else /* !WORDS_BIGENDIAN */
+#    define ngtcp2_ntohl64(N) ngtcp2_bswap64(N)
+#    define ngtcp2_htonl64(N) ngtcp2_bswap64(N)
+#  endif /* !WORDS_BIGENDIAN */
+#endif   /* !HAVE_BE64TOH */
 #if defined(WIN32)
 /* Windows requires ws2_32 library for ntonl family functions.  We
    define inline functions for those function so that we don't have