mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
encoding/cbor: support simd vectors
This commit is contained in:
@@ -630,6 +630,24 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er
|
|||||||
_marshal_into_encoder(e, any{rawptr(data), info.elem.id}, elem_ti) or_return
|
_marshal_into_encoder(e, any{rawptr(data), info.elem.id}, elem_ti) or_return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
|
case runtime.Type_Info_Simd_Vector:
|
||||||
|
err_conv(_encode_u64(e, u64(info.count), .Array)) or_return
|
||||||
|
|
||||||
|
if impl, ok := _tag_implementations_type[info.elem.id]; ok {
|
||||||
|
for i in 0..<info.count {
|
||||||
|
data := uintptr(v.data) + uintptr(i*info.elem_size)
|
||||||
|
impl->marshal(e, any{rawptr(data), info.elem.id}) or_return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
elem_ti := runtime.type_info_core(type_info_of(info.elem.id))
|
||||||
|
for i in 0..<info.count {
|
||||||
|
data := uintptr(v.data) + uintptr(i*info.elem_size)
|
||||||
|
_marshal_into_encoder(e, any{rawptr(data), info.elem.id}, elem_ti) or_return
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return _unsupported(v.id, nil)
|
return _unsupported(v.id, nil)
|
||||||
|
|||||||
@@ -604,6 +604,18 @@ _unmarshal_array :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header
|
|||||||
if out_of_space { return _unsupported(v, hdr) }
|
if out_of_space { return _unsupported(v, hdr) }
|
||||||
return
|
return
|
||||||
|
|
||||||
|
case reflect.Type_Info_Simd_Vector:
|
||||||
|
length, _ := err_conv(_decode_len_container(d, add)) or_return
|
||||||
|
if length > t.count {
|
||||||
|
return _unsupported(v, hdr)
|
||||||
|
}
|
||||||
|
|
||||||
|
da := mem.Raw_Dynamic_Array{rawptr(v.data), 0, length, allocator }
|
||||||
|
|
||||||
|
out_of_space := assign_array(d, &da, t.elem, length, growable=false) or_return
|
||||||
|
if out_of_space { return _unsupported(v, hdr) }
|
||||||
|
return
|
||||||
|
|
||||||
case: return _unsupported(v, hdr)
|
case: return _unsupported(v, hdr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ Foo :: struct {
|
|||||||
smallest: big.Int,
|
smallest: big.Int,
|
||||||
ignore_this: ^Foo `cbor:"-"`,
|
ignore_this: ^Foo `cbor:"-"`,
|
||||||
mat: matrix[4, 4]f32,
|
mat: matrix[4, 4]f32,
|
||||||
|
vec: #simd [4]f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
FooBar :: enum {
|
FooBar :: enum {
|
||||||
@@ -97,6 +98,7 @@ test_marshalling :: proc(t: ^testing.T) {
|
|||||||
small_onetwenty = -i128(max(u64)),
|
small_onetwenty = -i128(max(u64)),
|
||||||
ignore_this = &Foo{},
|
ignore_this = &Foo{},
|
||||||
mat = 1,
|
mat = 1,
|
||||||
|
vec = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
big.atoi(&f.biggest, "1234567891011121314151617181920")
|
big.atoi(&f.biggest, "1234567891011121314151617181920")
|
||||||
@@ -145,6 +147,12 @@ test_marshalling :: proc(t: ^testing.T) {
|
|||||||
"now": 1(1701117968),
|
"now": 1(1701117968),
|
||||||
"pos": 1212,
|
"pos": 1212,
|
||||||
"str": "Hellope",
|
"str": "Hellope",
|
||||||
|
"vec": [
|
||||||
|
2.0000,
|
||||||
|
2.0000,
|
||||||
|
2.0000,
|
||||||
|
2.0000
|
||||||
|
],
|
||||||
"yes": true,
|
"yes": true,
|
||||||
"comp": [
|
"comp": [
|
||||||
32.0000,
|
32.0000,
|
||||||
|
|||||||
Reference in New Issue
Block a user