-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patharch.bqn
43 lines (38 loc) · 2.03 KB
/
arch.bqn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# CPU architecture namespace, based on provided feature set argfeats
argfeats‿infer ← ⋈⟜0⍟(0=≠) •args
arches‿ReadDeps‿ReadNative‿ToUpper ← •Import "archutil.bqn"
# Process feature flags and detect architecture family
allfeats ← ∾ archfeats ← {𝕩.feats}¨ arches
AllNat ← ∊⟜allfeats⊸/ ReadNative
MaybeNat ← "NATIVE"⊸≡¨ (¬⊸/∾AllNat)⍟((0=≠)⊸(∨´)⊣) ⊢
arg ← ⟨"NONE"⟩⊸≢◶⟨⟩‿MaybeNat ToUpper argfeats
all ← "ALL"⊸≡¨ arg
!∘(∾"Unknown features:"<⊸∾' '∾¨/⟜arg)⍟(∨´) ¬all∨arg∊allfeats
"Incompatible features" ! ∨´ supp ← (all¬⊸/arg)⊸(∧´∊)¨ archfeats
archDesc ← ⊑ supp / arches
width‿VecType‿header ⇐ ⟨aname⇐name⟩ ← archDesc
# Parse dependencies for the chosen architecture
⟨feats, mat⟩ ⇐ {
TSort ← {{𝕊⍟(𝕩<○≠⊢)⟜(𝕩∾·/𝕨⊸<)𝕨∨∧´∘⊏⟜𝕨¨p}⟜/0¨p←𝕩} # Topological sort
# d is a list of extension dependency chains
u ← ⍷∾ d ← ReadDeps archDesc.ExtFile infer
u ⊏˜↩ TSort ∾¨ (⊢⊔○∾(¯1↓↑)¨) (<u)⊐¨d
# Unique feature flags including arch name
feats ⇐ ⟨aname⟩ ∾ u
# Make a dependency matrix: i‿j⊑m is 1 iff feature i depends on j
m ← (≥⌜˜↕∘≠)⊸×∨´×⌜˜¨(<u)∊¨d # Dependencies from file
m ∨˝∘∧⎉1‿∞˜⍟(⌈2⋆⁼≠)↩ # Transitive closure
mat ⇐ 1 ∾˘ 0¨∘⊏⊸∾ m # Plus base architecture
}
baseArch ⇐ ∨˝∘∧⟜mat (∨´all)◶⟨∊⟜arg,1¨⟩ feats
FeatInd ⇐ { # 𝕨 is 0 to allow features outside current architecture
i ← feats ⊐ 𝕩
m ← (i=≠feats)/○⥊𝕩
!∘(∾"Unknown architecture features:"<⊸∾' '∾¨/⟜m)⍟(∨´) ¬m∊allfeats
!∘(1↓·∾' '∾¨⟨"Features not in",aname,"architecture:"⟩∾⊢)⍟(0<≠)⍟𝕨 m
i
}
# For external tools, return base architecture as C compiler flags
GetCFlags ⇐ {𝕊:
"-m"⊸∾¨ ((-´"aA")×'A'⊸≤∧≤⟜'Z')⊸+ (baseArch ∧ (aname)⊸≢¨)⊸/ feats
}