File: avm_cpuinfo.h

package info (click to toggle)
avifile 1%3A0.7.48~20090503.ds-20.1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 8,340 kB
  • sloc: cpp: 57,239; ansic: 56,968; sh: 5,370; perl: 1,548; makefile: 1,263; asm: 569; awk: 234
file content (79 lines) | stat: -rw-r--r-- 1,750 bytes parent folder | download | duplicates (8)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef AVM_CPUINFO_H
#define AVM_CPUINFO_H

#include "avm_default.h"

AVM_BEGIN_NAMESPACE;

class CPU_Info
{
    double freq;
    bool have_tsc;
    bool have_mmx;
    bool have_mmxext;
    bool have_sse;
public:
    CPU_Info();
    ~CPU_Info();

    void Init();
    /**
     * Returns nonzero if the processor supports MMX instruction set.
     */
    bool HaveMMX() const {return have_mmx;}
    /**
     * Returns nonzero if the processor supports extended integer MMX instruction set
     ( Pentium-III, AMD Athlon and compatibles )
     */
    bool HaveMMXEXT() const {return have_mmxext;}
    /**
     * Returns nonzero if the processor supports 'SSE' floating-point SIMD instruction set
     ( Pentium-III and compatibles )
     */
    bool HaveSSE() const {return have_sse;}
    /**
     * Returns nonzero if the processor has time-stamp counter feature.
     */
    bool HaveTSC() const {return have_tsc;}
    /**
     * Returns processor frequency in kHz.
     */
    operator double() const {return freq;}
};

AVM_END_NAMESPACE;

extern AVMEXPORT avm::CPU_Info freq;

AVM_BEGIN_EXTERN_C;

static inline int avm_is_mmx_state()
{
#ifdef ARCH_X86
    if (freq.HaveMMX())
    {
	unsigned short tagword = 0;
	char b[28];
	__asm__ __volatile__ ("fnstenv (%0)\n\t" : : "r"(&b));
	tagword = *(unsigned short*) (b + 8);
	return (tagword != 0xffff);
    }
#endif
    return 0;
}

#ifdef AVM_COMPATIBLE
/**
 *  Returns duration of time interval between two timestamps, received
 *  with longcount() in miliseconds
 */
static inline float to_float(int64_t tend, int64_t tbegin)
{
    //return float((tend - tbegin) / (double)freq / 1000.);
    return float((double)(tend - tbegin) / 4294.967296);
}
#endif

AVM_END_EXTERN_C;

#endif // AVM_CPUINFO_H