Skip to content

Instantly share code, notes, and snippets.

@paniq
Created May 1, 2020 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paniq/76e13f62a0f1b35b945544317d651164 to your computer and use it in GitHub Desktop.
Save paniq/76e13f62a0f1b35b945544317d651164 to your computer and use it in GitHub Desktop.
using import testing
# test alignment
inline test-alignment (T)
let size alignment =
ptrtoint (getelementptr (nullof (mutable pointer T)) 1) u64
ptrtoint (getelementptr (nullof (mutable pointer (tuple bool T))) 0 1) u64
print T size alignment
if (size != (sizeof T))
print T "size mismatch:" (sizeof T) "!=" size
if (alignment != (alignof T))
print T "align mismatch:" (alignof T) "!=" alignment
test
== (alignof T) alignment
test
== (sizeof T) size
test-alignment (vector f32 3)
test-alignment (vector i8 3)
test-alignment (vector f32 9)
test-alignment (vector i8 11)
test-alignment (vector bool 32)
let i1 = (integer 1 true)
test-alignment (vector i1 32)
va-map
inline (i)
i := i + 1
test-alignment (integer i)
test-alignment (integer (i + 64))
test-alignment (integer (i + 64 * 2))
test-alignment (integer (i + 64 * 3))
va-range 64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment