Skip to content

Commit

Permalink
Simplify endian detection logic (onnx#5594)
Browse files Browse the repository at this point in the history
Simplify endian detection logic by removing if branches and leveraging
c++ syntax.

Reference:
https://github.com/pytorch/pytorch/blob/653c1564bf4c46d9758000ea70a610ee3699acf1/caffe2/operators/fused_rowwise_nbitfake_conversion_ops.h#L16-L19

### Motivation and Context

Code quality

---------

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
  • Loading branch information
justinchuby committed Sep 21, 2023
1 parent 81ec6a5 commit 3abb6b3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions onnx/common/platform_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

#pragma once

#include <cstdint>

namespace ONNX_NAMESPACE {

// Determine if the processor is little endian or not
inline bool is_processor_little_endian() {
int num = 1;
if (*(char*)&num == 1)
return true;
return false;
constexpr std::int32_t value = 1;
return reinterpret_cast<const std::uint8_t*>(&value)[0] == 1;
}

} // namespace ONNX_NAMESPACE

0 comments on commit 3abb6b3

Please sign in to comment.