aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2018-09-02 20:05:49 +0200
committerMichael Buesch <m@bues.ch>2018-09-03 22:08:21 +0200
commit211d6eb27b15259d03d36375cb76cd52c12046cc (patch)
treebc8cad45e97f77af92c07685e975d8eeaa2e280d
parent9a448c08749b383dcaffb4cd13b9c9d0d1aa4a33 (diff)
downloadawlsim-core-optimize.zip
awlsim-core-optimize.tar.xz
core/memory: Fix type punning warning on older compilerscore-optimize
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--awlsim/core/memory.pxd.in22
-rw-r--r--awlsim/core/memory.py34
2 files changed, 36 insertions, 20 deletions
diff --git a/awlsim/core/memory.pxd.in b/awlsim/core/memory.pxd.in
index 0ed439b..f634f9c 100644
--- a/awlsim/core/memory.pxd.in
+++ b/awlsim/core/memory.pxd.in
@@ -210,20 +210,30 @@ cdef AwlMemoryObject_asScalar_failed(AwlMemoryObject memObj)
cdef uint32_t AwlMemoryObject_asScalar(AwlMemoryObject memObj) except? 0x7FFFFFFF
cdef inline uint32_t AwlMemoryObject_asScalar1(AwlMemoryObject memObj):
- return <uint8_t>(memObj.dataBytes[0]) & 1u
+ cdef const uint8_t *dataBytes
+ dataBytes = &memObj.dataBytes[0]
+ return <uint8_t>(dataBytes[0]) & 1u
cdef inline uint32_t AwlMemoryObject_asScalar8(AwlMemoryObject memObj):
- return <uint8_t>(memObj.dataBytes[0])
+ cdef const uint8_t *dataBytes
+ dataBytes = &memObj.dataBytes[0]
+ return <uint8_t>(dataBytes[0])
cdef inline uint32_t AwlMemoryObject_asScalar16(AwlMemoryObject memObj):
- return be16toh((<uint16_t *>(&memObj.dataBytes[0]))[0])
+ cdef const uint8_t *dataBytes
+ dataBytes = &memObj.dataBytes[0]
+ return be16toh((<uint16_t *>dataBytes)[0])
cdef inline uint32_t AwlMemoryObject_asScalar24(AwlMemoryObject memObj):
- return ((<uint32_t>be16toh((<uint16_t *>(&memObj.dataBytes[0]))[0]) << 8) |
- <uint32_t>memObj.dataBytes[2])
+ cdef const uint8_t *dataBytes
+ dataBytes = &memObj.dataBytes[0]
+ return ((<uint32_t>be16toh((<uint16_t *>dataBytes)[0]) << 8) |
+ <uint32_t>dataBytes[2])
cdef inline uint32_t AwlMemoryObject_asScalar32(AwlMemoryObject memObj):
- return be32toh((<uint32_t *>(&memObj.dataBytes[0]))[0])
+ cdef const uint8_t *dataBytes
+ dataBytes = &memObj.dataBytes[0]
+ return be32toh((<uint32_t *>dataBytes)[0])
cdef bytearray AwlMemoryObject_asBytes(AwlMemoryObject memObj)
diff --git a/awlsim/core/memory.py b/awlsim/core/memory.py
index 7f49482..520f50f 100644
--- a/awlsim/core/memory.py
+++ b/awlsim/core/memory.py
@@ -850,52 +850,58 @@ make_AwlMemoryObject_fromScalar48 = lambda v: make_AwlMemoryObject_fromScalar(v,
#cdef AwlMemoryObject make_AwlMemoryObject_fromScalar1(int64_t value) except NULL: #@cy
#@cy cdef AwlMemoryObject memObj
-#@cy cdef uint32_t byteOffset
+#@cy cdef uint8_t *dataBytes
#@cy
#@cy memObj = alloc_AwlMemoryObject(1)
-#@cy memObj.dataBytes[0] = 1 if value else 0
+#@cy dataBytes = &memObj.dataBytes[0]
+#@cy dataBytes[0] = 1 if value else 0
#@cy return memObj
#cdef AwlMemoryObject make_AwlMemoryObject_fromScalar8(int64_t value) except NULL: #@cy
#@cy cdef AwlMemoryObject memObj
-#@cy cdef uint32_t byteOffset
+#@cy cdef uint8_t *dataBytes
#@cy
#@cy memObj = alloc_AwlMemoryObject(8)
-#@cy memObj.dataBytes[0] = <uint8_t>value
+#@cy dataBytes = &memObj.dataBytes[0]
+#@cy dataBytes[0] = <uint8_t>value
#@cy return memObj
#cdef AwlMemoryObject make_AwlMemoryObject_fromScalar16(int64_t value) except NULL: #@cy
#@cy cdef AwlMemoryObject memObj
-#@cy cdef uint32_t byteOffset
+#@cy cdef uint8_t *dataBytes
#@cy
#@cy memObj = alloc_AwlMemoryObject(16)
-#@cy (<uint16_t *>(&memObj.dataBytes[0]))[0] = htobe16(<uint16_t>value)
+#@cy dataBytes = &memObj.dataBytes[0]
+#@cy (<uint16_t *>dataBytes)[0] = htobe16(<uint16_t>value)
#@cy return memObj
#cdef AwlMemoryObject make_AwlMemoryObject_fromScalar24(int64_t value) except NULL: #@cy
#@cy cdef AwlMemoryObject memObj
-#@cy cdef uint32_t byteOffset
+#@cy cdef uint8_t *dataBytes
#@cy
#@cy memObj = alloc_AwlMemoryObject(24)
-#@cy (<uint16_t *>(&memObj.dataBytes[0]))[0] = htobe16(<uint16_t>(<uint32_t>value >> 8))
-#@cy memObj.dataBytes[2] = <uint8_t>value
+#@cy dataBytes = &memObj.dataBytes[0]
+#@cy (<uint16_t *>dataBytes)[0] = htobe16(<uint16_t>(<uint32_t>value >> 8))
+#@cy dataBytes[2] = <uint8_t>value
#@cy return memObj
#cdef AwlMemoryObject make_AwlMemoryObject_fromScalar32(int64_t value) except NULL: #@cy
#@cy cdef AwlMemoryObject memObj
-#@cy cdef uint32_t byteOffset
+#@cy cdef uint8_t *dataBytes
#@cy
#@cy memObj = alloc_AwlMemoryObject(32)
-#@cy (<uint32_t *>(&memObj.dataBytes[0]))[0] = htobe32(<uint32_t>value)
+#@cy dataBytes = &memObj.dataBytes[0]
+#@cy (<uint32_t *>dataBytes)[0] = htobe32(<uint32_t>value)
#@cy return memObj
#cdef AwlMemoryObject make_AwlMemoryObject_fromScalar48(int64_t value) except NULL: #@cy
#@cy cdef AwlMemoryObject memObj
-#@cy cdef uint32_t byteOffset
+#@cy cdef uint8_t *dataBytes
#@cy
#@cy memObj = alloc_AwlMemoryObject(48)
-#@cy (<uint32_t *>(&memObj.dataBytes[0]))[0] = htobe32(<uint32_t>(<uint64_t>value >> 16))
-#@cy (<uint16_t *>(&memObj.dataBytes[4]))[0] = htobe16(<uint16_t>value)
+#@cy dataBytes = &memObj.dataBytes[0]
+#@cy (<uint32_t *>dataBytes)[0] = htobe32(<uint32_t>(<uint64_t>value >> 16))
+#@cy (<uint16_t *>dataBytes)[2] = htobe16(<uint16_t>value)
#@cy return memObj
def make_AwlMemoryObject_fromGeneric(value, width): #@nocy
bues.ch cgit interface