~ubuntu-branches/debian/sid/upx-ucl/sid

« back to all changes in this revision

Viewing changes to src/acc/acclib/rdtsc.ch

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2006-06-13 21:23:23 UTC
  • mfrom: (1.3.1 upstream) (3.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20060613212323-343yzs4jt6vr5483
* New upstream version.
* Standards-Version: 3.7.2 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ACC -- Automatic Compiler Configuration
2
 
 
3
 
   Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
4
 
   All Rights Reserved.
5
 
 
6
 
   This software is a copyrighted work licensed under the terms of
7
 
   the GNU General Public License. Please consult the file "ACC_LICENSE"
8
 
   for details.
9
 
 
10
 
   Markus F.X.J. Oberhumer
11
 
   <markus@oberhumer.com>
12
 
   http://www.oberhumer.com/
13
 
 */
14
 
 
15
 
 
16
 
#define __ACCLIB_RDTSC_CH_INCLUDED 1
17
 
#if !defined(ACCLIB_PUBLIC)
18
 
#  define ACCLIB_PUBLIC(r,f)    r __ACCLIB_FUNCNAME(f)
19
 
#endif
20
 
 
21
 
#if defined(acc_int32e_t)
22
 
 
23
 
 
24
 
/*************************************************************************
25
 
// read TSC
26
 
**************************************************************************/
27
 
 
28
 
ACCLIB_PUBLIC(int, acc_tsc_read) (acc_uint32e_t* t)
29
 
{
30
 
#if ((ACC_ARCH_AMD64 || ACC_ARCH_IA32) && ACC_CC_GNUC)
31
 
    __asm__ __volatile__(
32
 
        "clc \n" ".byte 0x0f, 0x31\n"
33
 
        "movl %%eax,(%0)\n" "movl %%edx,4(%0)\n"
34
 
#  if (ACC_CC_GNUC >= 0x020000ul)
35
 
        : : "r" (t) : "cc", "memory", "eax", "edx"
36
 
#  else
37
 
        : : "r" (t) : "ax", "dx"
38
 
#  endif
39
 
    );
40
 
    return 0;
41
 
#elif (ACC_ARCH_IA32 && ACC_CC_INTELC) && defined(__linux__)
42
 
    __asm__ __volatile__(
43
 
        "clc \n" ".byte 0x0f, 0x31\n"
44
 
        "movl %%eax,(%0)\n" "movl %%edx,4(%0)\n"
45
 
        : : "r" (t) : "memory", "eax", "edx"
46
 
    );
47
 
    return 0;
48
 
#elif (ACC_ARCH_IA32 && (ACC_OS_DOS32 || ACC_OS_WIN32) && (ACC_CC_DMC || ACC_CC_INTELC || ACC_CC_MSC))
49
 
    ACC_UNUSED(t);
50
 
    __asm {
51
 
        mov ecx, t
52
 
        clc
53
 
#  if (ACC_CC_MSC && (_MSC_VER < 1200))
54
 
        _emit 0x0f
55
 
        _emit 0x31
56
 
#  else
57
 
        rdtsc
58
 
#  endif
59
 
        mov [ecx], eax
60
 
        mov [ecx+4], edx
61
 
    }
62
 
    return 0;
63
 
#else
64
 
    t[0] = t[1] = 0;
65
 
    return -1;
66
 
#endif
67
 
}
68
 
 
69
 
 
70
 
/*************************************************************************
71
 
// read and add TSC
72
 
**************************************************************************/
73
 
 
74
 
ACCLIB_PUBLIC(int, acc_tsc_read_add) (acc_uint32e_t* t)
75
 
{
76
 
#if ((ACC_ARCH_AMD64 || ACC_ARCH_IA32) && ACC_CC_GNUC)
77
 
    __asm__ __volatile__(
78
 
        "clc \n" ".byte 0x0f, 0x31\n"
79
 
        "addl %%eax,(%0)\n" "adcl $0,%%edx\n" "addl %%edx,4(%0)\n"
80
 
#  if (ACC_CC_GNUC >= 0x020000ul)
81
 
        : : "r" (t) : "cc", "memory", "eax", "edx"
82
 
#  else
83
 
        : : "r" (t) : "ax", "dx"
84
 
#  endif
85
 
    );
86
 
    return 0;
87
 
#elif (ACC_ARCH_IA32 && ACC_CC_INTELC) && defined(__linux__)
88
 
    __asm__ __volatile__(
89
 
        "clc \n" ".byte 0x0f, 0x31\n"
90
 
        "addl %%eax,(%0)\n" "adcl $0,%%edx\n" "addl %%edx,4(%0)\n"
91
 
        : : "r" (t) : "memory", "eax", "edx"
92
 
    );
93
 
    return 0;
94
 
#elif (ACC_ARCH_IA32 && (ACC_OS_DOS32 || ACC_OS_WIN32) && (ACC_CC_DMC || ACC_CC_INTELC || ACC_CC_MSC))
95
 
    ACC_UNUSED(t);
96
 
    __asm {
97
 
        mov ecx, t
98
 
        clc
99
 
#  if (ACC_CC_MSC && (_MSC_VER < 1200))
100
 
        _emit 0x0f
101
 
        _emit 0x31
102
 
#  else
103
 
        rdtsc
104
 
#  endif
105
 
        add [ecx], eax
106
 
        adc edx, 0
107
 
        add [ecx+4], edx
108
 
    }
109
 
    return 0;
110
 
#else
111
 
    acc_uint32e_t v[2];
112
 
    int r;
113
 
    r = acc_tsc_read(v);
114
 
    t[0] += v[0];
115
 
    if (t[0] < v[0]) t[1] += 1;
116
 
    t[1] += v[1];
117
 
    return r;
118
 
#endif
119
 
}
120
 
 
121
 
 
122
 
#endif /* defined(acc_int32e_t) */
123
 
 
124
 
 
125
 
/*
126
 
vi:ts=4:et
127
 
*/