X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fsparcv9cap.c;h=5f31d20bd07c47a9fdb073ec8e4141f137b002cc;hb=d9f5f07e286bfc7a2a81756199a3e94444e0f6ce;hp=7012f78604b294fd8dcc202b86058d312282e5d8;hpb=c06b0f3d5e20032e323903f754953fdfe246aa64;p=oweals%2Fopenssl.git diff --git a/crypto/sparcv9cap.c b/crypto/sparcv9cap.c index 7012f78604..5f31d20bd0 100644 --- a/crypto/sparcv9cap.c +++ b/crypto/sparcv9cap.c @@ -16,7 +16,7 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_U int bn_mul_mont_fpu(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num); int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num); - if (OPENSSL_sparcv9cap_P&(SPARCV9_PREFER_FPU|SPARCV9_VIS1) == + if ((OPENSSL_sparcv9cap_P&(SPARCV9_PREFER_FPU|SPARCV9_VIS1)) == (SPARCV9_PREFER_FPU|SPARCV9_VIS1)) return bn_mul_mont_fpu(rp,ap,bp,np,n0,num); else @@ -25,7 +25,7 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_U unsigned long OPENSSL_rdtsc(void) { - unsigned long OPENSSL_rdtick(void); + unsigned long _sparcv9_rdtick(void); if (OPENSSL_sparcv9cap_P&SPARCV9_TICK_PRIVILEGED) #if defined(__sun) && defined(__SVR4) @@ -34,13 +34,14 @@ unsigned long OPENSSL_rdtsc(void) return 0; #endif else - return OPENSSL_rdtick(); + return _sparcv9_rdtick(); } #if defined(__sun) && defined(__SVR4) #include #include +#include typedef di_node_t (*di_init_t)(const char *,uint_t); typedef void (*di_fini_t)(di_node_t); @@ -55,21 +56,22 @@ static int walk_nodename(di_node_t node, di_node_name_t di_node_name) /* This is expected to catch all UltraSPARC flavors prior T1 */ if (!strcmp (name,"SUNW,UltraSPARC") || - !strncmp(name,"SUNW,UltraSPARC-I",17)) + !strncmp(name,"SUNW,UltraSPARC-I",17)) /* covers II,III,IV */ { OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU|SPARCV9_VIS1; - /* %tick is privileged only on UltraSPARC-I/II */ + /* %tick is privileged only on UltraSPARC-I/II, but not IIe */ if (name[14]!='\0' && name[17]!='\0' && name[18]!='\0') OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED; return DI_WALK_TERMINATE; } - /* This is expected to catch remaining UltraSPARC T1 */ + /* This is expected to catch remaining UltraSPARCs, such as T1 */ else if (!strncmp(name,"SUNW,UltraSPARC",15)) { - OPENSSL_sparcv9cap_P |= SPARCV9_VIS1; OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED; + + return DI_WALK_TERMINATE; } return DI_WALK_CONTINUE; @@ -78,15 +80,38 @@ static int walk_nodename(di_node_t node, di_node_name_t di_node_name) void OPENSSL_cpuid_setup(void) { void *h; - char *e; + char *e,si[256]; + static int trigger=0; - if (e=getenv("OPENSSL_sparcv9cap")) + if (trigger) return; + trigger=1; + + if ((e=getenv("OPENSSL_sparcv9cap"))) { OPENSSL_sparcv9cap_P=strtoul(e,NULL,0); return; } - if (h = dlopen("libdevinfo.so.1",RTLD_LAZY)) do + if (sysinfo(SI_MACHINE,si,sizeof(si))>0) + { + if (strcmp(si,"sun4v")) + /* FPU is preferred for all CPUs, but US-T1/2 */ + OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU; + } + + if (sysinfo(SI_ISALIST,si,sizeof(si))>0) + { + if (strstr(si,"+vis")) + OPENSSL_sparcv9cap_P |= SPARCV9_VIS1; + if (strstr(si,"+vis2")) + { + OPENSSL_sparcv9cap_P |= SPARCV9_VIS2; + OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED; + return; + } + } + + if ((h = dlopen("libdevinfo.so.1",RTLD_LAZY))) do { di_init_t di_init; di_fini_t di_fini; @@ -110,24 +135,20 @@ void OPENSSL_cpuid_setup(void) if (h) dlclose(h); } -#elif defined(__linux) +#else void OPENSSL_cpuid_setup(void) { char *e; - if (e=getenv("OPENSSL_sparcv9cap")) + if ((e=getenv("OPENSSL_sparcv9cap"))) { - OPENSSL_sparcv9cap_P=strtoul(env,NULL,0); + OPENSSL_sparcv9cap_P=strtoul(e,NULL,0); return; } - /* Linux apparently supports UltraSPARC-I/II/III only */ + /* For now we assume that the rest supports UltraSPARC-I* only */ OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU|SPARCV9_VIS1; } -#else - -void OPENSSL_cpuid_setup(void) {} - #endif