aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ward <james.ward@arm.com>2023-01-25 15:51:27 +0000
committerJames Ward <james.ward@arm.com>2023-01-27 12:55:48 +0000
commit80905bba37ce55e8db293b1405a78b63dc1855cb (patch)
treeedf3d19a8959c5cb080e0d8765d460569afbf4f8
parentea00fd0f76c39c650eececc1d640126584357095 (diff)
downloadserialization_lib-80905bba37ce55e8db293b1405a78b63dc1855cb.tar.gz
Remove zero pad from float attrribute serialization
* For Clamp/Pad float attributes * Necessary for the outputs from Python and C++ code to be consistent Signed-off-by: James Ward <james.ward@arm.com> Change-Id: I41530aa1805968becd861e4dee190a88d1973cec
-rw-r--r--src/tosa_serialization_handler.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/tosa_serialization_handler.cpp b/src/tosa_serialization_handler.cpp
index 2062522..d84e0ab 100644
--- a/src/tosa_serialization_handler.cpp
+++ b/src/tosa_serialization_handler.cpp
@@ -619,11 +619,16 @@ tosa_err_t TosaSerializationHandler::Deserialize(const uint8_t* buf)
return TOSA_OK;
}
-std::vector<uint8_t> float_to_u8_wrapper(float f_in)
+std::vector<uint8_t> float_to_u8_helper(float f_in)
{
- const std::vector<float> f_vec{ f_in };
+ // Push back a single float value to the buffer with *NO PADDING*
+ // Therefore ConvertF32toU8 function not used
std::vector<uint8_t> u8_out;
- TosaSerializationHandler::ConvertF32toU8(f_vec, u8_out);
+ uint32_t* val_u32 = reinterpret_cast<uint32_t*>(&f_in);
+ u8_out.push_back(*val_u32 & 0xFF);
+ u8_out.push_back((*val_u32 >> 8) & 0xFF);
+ u8_out.push_back((*val_u32 >> 16) & 0xFF);
+ u8_out.push_back((*val_u32 >> 24) & 0xFF);
return u8_out;
}
@@ -691,7 +696,7 @@ tosa_err_t TosaSerializationHandler::Serialize()
break;
#define DEF_ARGS_S_STR(NAME, V) , _builder.CreateString(reinterpret_cast<Tosa##NAME*>(op->GetAttribute())->V().c_str())
#define DEF_ARGS_S_FP_as_U8(NAME, V) \
- , _builder.CreateVector<uint8_t>(float_to_u8_wrapper(reinterpret_cast<Tosa##NAME*>(op->GetAttribute())->V()))
+ , _builder.CreateVector<uint8_t>(float_to_u8_helper(reinterpret_cast<Tosa##NAME*>(op->GetAttribute())->V()))
#define DEF_ARGS_S_DEFAULT(NAME, V) , reinterpret_cast<Tosa##NAME*>(op->GetAttribute())->V()
#define DEF_ARGS_S_int32_t(NAME, V) DEF_ARGS_S_DEFAULT(NAME, V)
#define DEF_ARGS_S_float(NAME, V) DEF_ARGS_S_FP_as_U8(NAME, V)