@@ -4,13 +4,46 @@ void reg(int64_t id, int64_t name, int32_t arity){
44 dx (Asn (sc (Ku (name )),l ));
55}
66void libs (void ){ //encode strings with: https://play.golang.org/p/4ethx6OEVCR
7- reg (0 ,846033518ull ,1 ); //nrm2
7+ #ifdef BLAS
8+ reg (0 , 846033518ull ,1 ); //nrm2
9+ reg (1 ,1836413793ull ,1 ); //asum
10+ reg (2 ,2019650921ull ,1 ); //imax
11+ #endif
812 //reg(1,...);
913 //reg(2,...);
1014}
15+ int64_t fzvec (int64_t x ){
16+ int32_t xt = tp (x );
17+ if (xt < 16 ){x = Enl (x );xt = tp (x );}
18+ if (xt < Ft ){x = Add (Kf (0.0 ),x );}
19+ if (xt > Zt )trap ();
20+ return x ;
21+ }
22+
23+ #ifdef BLAS
24+ double cblas_dnrm2 (int ,double * ,int );
25+ double cblas_dasum (int ,double * ,int );
26+ int cblas_idamax (int ,double * ,int );
27+ int cblas_izamax (int ,double * ,int );
28+ #endif
29+
30+ #define fp (x ) ((double*)(M_+(int32_t)x))
31+
1132int64_t cnative (int64_t x , int64_t y ){
33+ int32_t xt ,xn ,i ;
34+ double r ;
1235 switch (x ){ //switch registered function id
13- case 0 : printf ("todo call blas nrm2\n" ); return y ; break ;
36+ #ifdef BLAS
37+ case 0 :x = fzvec (Fst (y ));xn = nn (x );if (xt == Zt )xn *=2 ;
38+ r = cblas_dnrm2 (xn ,fp (x ),1 );
39+ dx (x );return Kf (r );
40+ case 1 :x = fzvec (Fst (y ));xn = nn (x );if (xt == Zt )xn *=2 ;
41+ r = cblas_dasum (xn ,fp (x ),1 );
42+ dx (x );return Kf (r );
43+ case 2 :x = fzvec (Fst (y ));xn = nn (x );
44+ i = tp (x )== Ft ?cblas_idamax (xn ,fp (x ),1 ):cblas_izamax (xn ,fp (x ),1 );
45+ dx (x );return Ki (i );
46+ #endif
1447 default : return y ;
1548}}
1649
0 commit comments