fixes
This commit is contained in:
parent
43e07fcbac
commit
3a64dc7f7c
10 changed files with 19 additions and 97 deletions
|
|
@ -32,18 +32,15 @@ func Linear(max_size uintptr) Arena {
|
|||
ptr := &data[offset]
|
||||
offset += aligned
|
||||
return unsafe.Pointer(ptr), nil
|
||||
|
||||
case ACTION_RESET:
|
||||
clear(data)
|
||||
offset = 0
|
||||
|
||||
case ACTION_SAVE:
|
||||
*watermark = offset
|
||||
case ACTION_RESTORE:
|
||||
offset = *watermark
|
||||
|
||||
default:
|
||||
panic("unimplemented action: " + a.String())
|
||||
panic("linear: unimplemented action - " + a.String())
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
|
@ -64,19 +61,16 @@ func Pool[T any](base_capacity uintptr) Arena {
|
|||
case ACTION_ALLOC:
|
||||
pointers = append(pointers, mem.ZeroValue[T]())
|
||||
return unsafe.Pointer(&pointers[len(pointers)-1]), nil
|
||||
|
||||
case ACTION_RESET:
|
||||
clear(pointers)
|
||||
pointers = pointers[:0]
|
||||
|
||||
case ACTION_SAVE:
|
||||
*watermark = uintptr(len(pointers))
|
||||
|
||||
case ACTION_RESTORE:
|
||||
clear(pointers[*watermark:])
|
||||
pointers = pointers[:*watermark]
|
||||
|
||||
default:
|
||||
panic("pool: unimplemented action - " + a.String())
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
|
@ -124,7 +118,6 @@ func Chunked(chunk_size uintptr) Arena {
|
|||
c.offset += aligned
|
||||
|
||||
return unsafe.Pointer(ptr), nil
|
||||
|
||||
case ACTION_RESET:
|
||||
for _, g := range groups {
|
||||
for i := range len(g) {
|
||||
|
|
@ -134,7 +127,6 @@ func Chunked(chunk_size uintptr) Arena {
|
|||
clear(c.data)
|
||||
}
|
||||
}
|
||||
|
||||
case ACTION_SAVE:
|
||||
for _, g := range groups {
|
||||
for i := range len(g) {
|
||||
|
|
@ -142,7 +134,6 @@ func Chunked(chunk_size uintptr) Arena {
|
|||
c.saved = c.offset
|
||||
}
|
||||
}
|
||||
|
||||
case ACTION_RESTORE:
|
||||
for _, g := range groups {
|
||||
for i := range len(g) {
|
||||
|
|
@ -150,9 +141,8 @@ func Chunked(chunk_size uintptr) Arena {
|
|||
c.offset = c.saved
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
panic("unimplemented action: " + a.String())
|
||||
panic("chunked: unimplemented action - " + a.String())
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
|
@ -183,6 +173,7 @@ func Region(arena Arena) Arena {
|
|||
|
||||
// Split wraps two [[Arena]]s, dispatching allocations to a particular one based on the requested size.
|
||||
func Split(split_size uintptr, smaller, larger Arena) Arena {
|
||||
var watermarks [2]uintptr
|
||||
return func(a Action, size, align uintptr, watermark *uintptr) (unsafe.Pointer, error) {
|
||||
switch a {
|
||||
case ACTION_ALLOC:
|
||||
|
|
@ -190,17 +181,17 @@ func Split(split_size uintptr, smaller, larger Arena) Arena {
|
|||
return smaller(a, size, align, watermark)
|
||||
}
|
||||
return larger(a, size, align, watermark)
|
||||
|
||||
case ACTION_RESET:
|
||||
Reset(smaller)
|
||||
Reset(larger)
|
||||
|
||||
case ACTION_SAVE:
|
||||
panic("split: saving is not supported")
|
||||
watermarks[0] = Save(smaller)
|
||||
watermarks[1] = Save(larger)
|
||||
case ACTION_RESTORE:
|
||||
panic("split: restoring is not supported")
|
||||
|
||||
Restore(smaller, watermarks[0])
|
||||
Restore(larger, watermarks[1])
|
||||
default:
|
||||
panic("split: unimplemented action - " + a.String())
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
|
|
|||
26
asm/asm.go
26
asm/asm.go
|
|
@ -1,26 +0,0 @@
|
|||
package asm
|
||||
|
||||
type Call struct {
|
||||
registers
|
||||
fn uintptr
|
||||
sp uintptr
|
||||
stack [128]uintptr
|
||||
}
|
||||
|
||||
func PrepareCall(fn uintptr) Call {
|
||||
return Call{fn: fn}
|
||||
}
|
||||
|
||||
func (c *Call) Push(v uintptr) {
|
||||
c.stack[c.sp] = v
|
||||
c.sp += 1
|
||||
}
|
||||
|
||||
func (c *Call) Pop() uintptr {
|
||||
c.sp -= 1
|
||||
return c.stack[c.sp]
|
||||
}
|
||||
|
||||
func (c *Call) Do() {
|
||||
perform_call(c)
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package asm
|
||||
|
||||
type registers struct {
|
||||
R0, R1, R2, R3, R4,
|
||||
R5, R6, R7, R8, R9,
|
||||
R10, R11, R12, R13, R14,
|
||||
R15, R16, R17, R19, R20,
|
||||
R21, R22, R23, R24, R25,
|
||||
R26, R27, R29, R30, R31 uintptr
|
||||
|
||||
F0, F1, F2, F3, F4,
|
||||
F5, F6, F7, F8, F9,
|
||||
F10 float64
|
||||
}
|
||||
|
||||
func perform_call(c *Call)
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package asm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
_ "unsafe"
|
||||
|
||||
"git.brut.systems/judah/xx/asm"
|
||||
)
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
call := asm.PrepareCall(0)
|
||||
call.R1 = 10
|
||||
call.R2 = 10
|
||||
call.Do()
|
||||
|
||||
result := call.R0
|
||||
expected := uintptr(8)
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected %d, got %d", expected, result)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,3 @@ func Assert(cond bool) {
|
|||
panic("assertion failed")
|
||||
}
|
||||
}
|
||||
|
||||
func Unreachable() {
|
||||
panic("unreachable")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,19 +57,19 @@ func (p Pinned[T]) Sub(amount uintptr) Pinned[T] {
|
|||
}
|
||||
|
||||
func (p Pinned[T]) Aligned() bool {
|
||||
return mem.Aligned(uintptr(p.base), mem.AlignOf[T]())
|
||||
return mem.Aligned(uintptr(p.base), mem.Alignof[T]())
|
||||
}
|
||||
|
||||
func (p Pinned[T]) AlignForward() Pinned[T] {
|
||||
return Pinned[T]{
|
||||
base: unsafe.Pointer(mem.AlignForward(uintptr(p.base), mem.AlignOf[T]())),
|
||||
base: unsafe.Pointer(mem.AlignForward(uintptr(p.base), mem.Alignof[T]())),
|
||||
pinner: p.pinner,
|
||||
}
|
||||
}
|
||||
|
||||
func (p Pinned[T]) AlignBackward() Pinned[T] {
|
||||
return Pinned[T]{
|
||||
base: unsafe.Pointer(mem.AlignBackward(uintptr(p.base), mem.AlignOf[T]())),
|
||||
base: unsafe.Pointer(mem.AlignBackward(uintptr(p.base), mem.Alignof[T]())),
|
||||
pinner: p.pinner,
|
||||
}
|
||||
}
|
||||
|
|
@ -83,5 +83,5 @@ func (p Pinned[T]) Store(value T) {
|
|||
}
|
||||
|
||||
func (p Pinned[T]) Nth(index int) T {
|
||||
return p.Add(uintptr(index) * mem.SizeOf[T]()).Load()
|
||||
return p.Add(uintptr(index) * mem.Sizeof[T]()).Load()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ type Of[T anystruct] struct {
|
|||
}
|
||||
|
||||
func (u Of[T]) Size() uintptr {
|
||||
return mem.SizeOf[T]()
|
||||
return mem.Sizeof[T]()
|
||||
}
|
||||
|
||||
// String returns the string representation of a union.
|
||||
|
|
@ -88,7 +88,7 @@ func Is[E any, T anystruct](u Of[T]) bool {
|
|||
// Use [SetSafe] for more safety checks.
|
||||
func Set[V any, T anystruct](u *Of[T], value V) {
|
||||
if u.mem == nil {
|
||||
u.mem = make([]byte, mem.SizeOf[T]())
|
||||
u.mem = make([]byte, mem.Sizeof[T]())
|
||||
}
|
||||
|
||||
*(*V)(unsafe.Pointer(&u.mem[0])) = value
|
||||
|
|
@ -101,7 +101,7 @@ func Set[V any, T anystruct](u *Of[T], value V) {
|
|||
// Use [Set] for fewer safety checks.
|
||||
func SetSafe[V any, T anystruct](u *Of[T], value V) error {
|
||||
if u.mem == nil {
|
||||
u.mem = make([]byte, mem.SizeOf[T]())
|
||||
u.mem = make([]byte, mem.Sizeof[T]())
|
||||
}
|
||||
|
||||
vt := reflect.TypeFor[V]()
|
||||
|
|
|
|||
4
xx.go
4
xx.go
|
|
@ -18,10 +18,10 @@ func New[T any](expr T) *T {
|
|||
//
|
||||
// Copy panics if src is smaller than dst.
|
||||
func Copy[TDst any, TSrc any](dst *TDst, src *TSrc) *TDst {
|
||||
if mem.SizeOf[TSrc]() < mem.SizeOf[TDst]() {
|
||||
if mem.Sizeof[TSrc]() < mem.Sizeof[TDst]() {
|
||||
panic("copy: size of src must be >= dst")
|
||||
}
|
||||
mem.Copy(unsafe.Pointer(dst), unsafe.Pointer(src), mem.SizeOf[TDst]())
|
||||
mem.Copy(unsafe.Pointer(dst), unsafe.Pointer(src), mem.Sizeof[TDst]())
|
||||
return dst
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func TestNew(t *testing.T) {
|
|||
t.Fail()
|
||||
}
|
||||
|
||||
if unsafe.Sizeof(*a) != mem.SizeOf[uint32]() {
|
||||
if unsafe.Sizeof(*a) != mem.Sizeof[uint32]() {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue