Fix minor issue, clean lut code

Resolves: [COMPMID-6799]
Signed-off-by: Mohammed Suhail Munshi <MohammedSuhail.Munshi@arm.com>
Change-Id: I47baeeea75f1d03609d1fa1e9a10d2f53d5694f7
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10969
Benchmark: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
diff --git a/src/core/helpers/LUTManager.cpp b/src/core/helpers/LUTManager.cpp
index 2f1746e..06e35ee 100644
--- a/src/core/helpers/LUTManager.cpp
+++ b/src/core/helpers/LUTManager.cpp
@@ -29,17 +29,22 @@
 #ifdef __aarch64__
 namespace
 {
+
 void init_lut_fp16(ActivationLayerInfo::LookupTable65536 *lut)
 {
-    for (uint16_t i = 0; i < lut->size() - 1; ++i)
+    union Element
     {
-        const float16_t *v = reinterpret_cast<float16_t *>(&i);
-        (*lut)[i]          = 1.f / (1.f + std::exp(-*v));
+        uint16_t  i = 0;
+        float16_t fp;
+    } item;
+    // Fill lut by iterating over all 16 bit values using the union.
+    while (true)
+    {
+        (*lut)[item.i] = 1.f / (1.f + std::exp(-item.fp));
+        if (item.i == 65535)
+            break;
+        item.i++;
     }
-    // Final value should be filled outside of loop to avoid overflows.
-    const uint16_t   i = lut->size() - 1;
-    const float16_t *v = reinterpret_cast<const float16_t *>(&i);
-    (*lut)[i]          = 1.f / (1.f + std::exp(-*v));
 }
 } // namespace