diff --git a/lib/libhac/include/nn/hac/Result.h b/lib/libhac/include/nn/hac/Result.h new file mode 100644 index 0000000..f13587a --- /dev/null +++ b/lib/libhac/include/nn/hac/Result.h @@ -0,0 +1,39 @@ +#pragma once +#include + +namespace nn +{ +namespace hac +{ + class Result + { + public: + Result(); + Result(uint32_t result); + Result(uint32_t module_num, uint32_t desc, uint32_t sub_desc); + + void operator=(const Result& other); + bool operator==(const Result& other) const; + bool operator!=(const Result& other) const; + + bool isSuccess() const; + bool isFailure() const; + + uint32_t getInnerValue() const; + uint32_t getModuleNum() const; + uint32_t getDescription() const; + uint32_t getSubDescription() const; + + private: + static const uint32_t kModuleNumBitWidth = 9; + static const uint32_t kModuleNumBitPos = 0; + static const uint32_t kDescriptionBitWidth = 13; + static const uint32_t kDescriptionBitPos = 9; + static const uint32_t kSubDescriptionBitWidth = 10; + static const uint32_t kSubDescriptionBitPos = 22; + inline uint32_t bitWidthToMask(uint32_t bit_width) const { return _BIT(bit_width) - 1; } + + uint32_t mResult; + }; +} +} \ No newline at end of file diff --git a/lib/libhac/libhac.vcxproj b/lib/libhac/libhac.vcxproj index 067835b..fa7d25c 100644 --- a/lib/libhac/libhac.vcxproj +++ b/lib/libhac/libhac.vcxproj @@ -68,6 +68,7 @@ + @@ -110,6 +111,7 @@ + diff --git a/lib/libhac/libhac.vcxproj.filters b/lib/libhac/libhac.vcxproj.filters index de979d9..2099435 100644 --- a/lib/libhac/libhac.vcxproj.filters +++ b/lib/libhac/libhac.vcxproj.filters @@ -186,6 +186,9 @@ Header Files + + Header Files + @@ -302,5 +305,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/lib/libhac/source/Result.cpp b/lib/libhac/source/Result.cpp new file mode 100644 index 0000000..da06c05 --- /dev/null +++ b/lib/libhac/source/Result.cpp @@ -0,0 +1,62 @@ +#include + +nn::hac::Result::Result() : + mResult(0) +{} + +nn::hac::Result::Result(uint32_t result) : + mResult(result) +{} + +nn::hac::Result::Result(uint32_t module_num, uint32_t desc, uint32_t sub_desc) : + mResult(0) +{ + mResult |= (module_num & bitWidthToMask(kModuleNumBitWidth)) << kModuleNumBitPos; + mResult |= (desc & bitWidthToMask(kDescriptionBitWidth)) << kDescriptionBitPos; + mResult |= (sub_desc & bitWidthToMask(kSubDescriptionBitWidth)) << kSubDescriptionBitPos; +} + +void nn::hac::Result::operator=(const Result & other) +{ + mResult = other.mResult; +} + +bool nn::hac::Result::operator==(const Result & other) const +{ + return mResult == other.mResult; +} + +bool nn::hac::Result::operator!=(const Result & other) const +{ + return !(*this == other); +} + +bool nn::hac::Result::isSuccess() const +{ + return mResult == 0; +} + +bool nn::hac::Result::isFailure() const +{ + return !isSuccess(); +} + +uint32_t nn::hac::Result::getInnerValue() const +{ + return mResult; +} + +uint32_t nn::hac::Result::getModuleNum() const +{ + return (mResult >> kModuleNumBitPos) & bitWidthToMask(kModuleNumBitWidth); +} + +uint32_t nn::hac::Result::getDescription() const +{ + return (mResult >> kDescriptionBitPos) & bitWidthToMask(kDescriptionBitWidth); +} + +uint32_t nn::hac::Result::getSubDescription() const +{ + return (mResult >> kSubDescriptionBitPos) & bitWidthToMask(kSubDescriptionBitWidth); +}