mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-19 13:21:41 +00:00
adds more tests
This commit is contained in:
@@ -111,3 +111,61 @@ for q in 0..500:
|
||||
y[i].a = q
|
||||
doAssert(cast[int](y[i]) mod alignof(MyType32) == 0)
|
||||
|
||||
# Additional tests: allocate custom aligned objects using `new`
|
||||
type
|
||||
MyType64 = object
|
||||
a{.align(64).}: int
|
||||
|
||||
var z: array[10, ref MyType64]
|
||||
for q in 0..500:
|
||||
for i in 0..<z.len:
|
||||
new z[i]
|
||||
z[i].a = q
|
||||
doAssert(cast[int](z[i]) mod alignof(MyType64) == 0)
|
||||
|
||||
type
|
||||
MyType128 = object
|
||||
a{.align(128).}: int
|
||||
|
||||
var w: array[10, ref MyType128]
|
||||
for q in 0..500:
|
||||
for i in 0..<w.len:
|
||||
new w[i]
|
||||
w[i].a = q
|
||||
doAssert(cast[int](w[i]) mod alignof(MyType128) == 0)
|
||||
|
||||
# Nested aligned-object tests
|
||||
type
|
||||
Inner128 = object
|
||||
v {.align(128).}: byte
|
||||
|
||||
OuterWithInner = object
|
||||
prefix: int
|
||||
inner: Inner128
|
||||
|
||||
var outerArr: array[8, ref OuterWithInner]
|
||||
for q in 0..200:
|
||||
for i in 0..<outerArr.len:
|
||||
new outerArr[i]
|
||||
# write to inner to ensure it's allocated
|
||||
outerArr[i].inner.v = cast[byte](q and 0xFF)
|
||||
doAssert(cast[uint](addr outerArr[i].inner) mod uint(alignof(Inner128)) == 0)
|
||||
|
||||
# Nested two-level alignment
|
||||
type
|
||||
DeepInner = object
|
||||
b {.align(128).}: int
|
||||
|
||||
Mid = object
|
||||
di: DeepInner
|
||||
|
||||
Top = object
|
||||
m: Mid
|
||||
|
||||
var topArr: array[4, ref Top]
|
||||
for q in 0..100:
|
||||
for i in 0..<topArr.len:
|
||||
new topArr[i]
|
||||
topArr[i].m.di.b = q
|
||||
doAssert(cast[uint](addr topArr[i].m.di) mod uint(alignof(DeepInner)) == 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user