Skip to content

Commit

Permalink
merge updates from wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
jcosborn committed Nov 16, 2024
1 parent bcc38d2 commit 17401d1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/physics/spinOld.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template index*[T,I](x: typedesc[Spin[T]], i: typedesc[I]): typedesc =
index(T.type, I.type)

template `[]`*[T](x: Spin, i: T): untyped =
when T is Spin:
when T is Spin2:
x[][i[]]
elif T.isWrapper:
#indexed(x, i)
Expand All @@ -43,8 +43,8 @@ template `[]`*[T](x: Spin, i: T): untyped =
x[][i]
template `[]`*(x: Spin, i,j: typed): untyped = x[][i,j]
#template `[]=`*[T](x: Spin, i: T; y: typed) =
proc `[]=`*[T](x: Spin, i: T; y: auto) =
when T is Spin:
proc `[]=`*[T](x: var Spin, i: T; y: auto) =
when T is Spin2:
x[][i[]] = y
elif T.isWrapper:
#indexed(x, i)
Expand Down Expand Up @@ -211,6 +211,8 @@ template spinVector*(x: static[int], a: untyped): untyped =
#let t = asSpin(t1)
#static: echo "spinVector2"
#t
template spinVector*[T](x: static[int], a: typedesc[T]): untyped =
asSpin(asVectorArray(x, type T))
template spinMatrix*[T](x,y:static[int], a: untyped): untyped =
const
I:int = x
Expand Down Expand Up @@ -315,6 +317,8 @@ const

template I(x: typed): untyped =
newImag(1)*x
template mI(x: typed): untyped =
newImag(-1)*x

proc spproj1p*(r: var auto, x: auto) =
## r: HalfFermion
Expand Down
41 changes: 37 additions & 4 deletions src/simd.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import simdGcc
#export simdGcc
import base/metaUtils
import math
import math, macros

import simd/simdWrap
export simdWrap
Expand All @@ -12,10 +12,17 @@ import base/stdUtils
import simd/simdArray
export simdArray

template msa(T,N,F: untyped) {.dirty,used.} =
makeSimdArray(`T Obj`, N, F)
type T* = Simd[`T Obj`]
#template msa(T,N,F: untyped) {.dirty,used.} =
template msa(T: untyped, N: static[int], F: typedesc) {.dirty,used.} =
#static: echo "msa: ", N, " ", F.type
#makeSimdArray(N, F, `T Obj`)
#template `T Array` = discard
#makeSimdArray(`T Obj`, N, F)
when declared SimdArrayObj:
type `T Obj`* = SimdArrayObj[N,F]
else:
makeSimdArray(`T Obj`, N, F)
type T* = Simd[`T Obj`]
type `T Array`* = `T Obj`
#static: echo "made type", $T

Expand Down Expand Up @@ -92,13 +99,19 @@ when true:
msa(SimdS2, 2, float32)
when not declared(SimdD2):
msa(SimdD2, 2, float64)
when not declared(SimdS2Obj):
type SimdS2Obj* = `[]`(SimdS2)
when not declared(SimdD2Obj):
type SimdD2Obj* = `[]`(SimdD2)

#when VLEN>=1:
when true:
msa(SimdS1, 1, float32)
msa(SimdD1, 1, float64)
when not declared(SimdS1Obj):
type SimdS1Obj* = `[]`(SimdS1)
when not declared(SimdD1Obj):
type SimdD1Obj* = `[]`(SimdD1)


## mixed precision assignment
Expand Down Expand Up @@ -321,4 +334,24 @@ template assignX*(x: var Simd, y: Simd2) =
debugType: y
assign(x[], y[])

macro simdObjType*(N: static int, T: typedesc): auto =
#echo T.repr
let p = if T.repr == "float32": "S" else: "D"
result = ident("Simd" & p & $N & "Obj")
#echo result

type
SimdObjType*[N:static int, T] = simdObjType(N,T)

when not declared SimdArrayObj:
type SimdArrayObj*[N:static int,T] = SimdObjType[N,T]

#[
template toDoubleImpl*(x: T): auto =
mixin simdObjType, assign
when F is float64: x
else:
type D = simdObjType(N, float64)
var r {.noInit.}: D
assign(r, x)
]#

0 comments on commit 17401d1

Please sign in to comment.