Subversion Repositories HelenOS

Rev

Rev 2726 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2726 Rev 4687
1
/*++
1
/*++
2
 
2
 
3
Copyright (c) 1998  Intel Corporation
3
Copyright (c) 1998  Intel Corporation
4
 
4
 
5
Module Name:
5
Module Name:
6
 
6
 
7
    math.c
7
    math.c
8
 
8
 
9
Abstract:
9
Abstract:
10
 
10
 
11
 
11
 
12
 
12
 
13
 
13
 
14
Revision History
14
Revision History
15
 
15
 
16
--*/
16
--*/
17
 
17
 
18
#include "lib.h"
18
#include "lib.h"
19
 
19
 
20
 
20
 
21
//
21
//
22
// Declare runtime functions
22
// Declare runtime functions
23
//
23
//
24
 
24
 
25
#ifdef RUNTIME_CODE
25
#ifdef RUNTIME_CODE
26
#pragma RUNTIME_CODE(LShiftU64)
26
#pragma RUNTIME_CODE(LShiftU64)
27
#pragma RUNTIME_CODE(RShiftU64)
27
#pragma RUNTIME_CODE(RShiftU64)
28
#pragma RUNTIME_CODE(MultU64x32)
28
#pragma RUNTIME_CODE(MultU64x32)
29
#pragma RUNTIME_CODE(DivU64x32)
29
#pragma RUNTIME_CODE(DivU64x32)
30
#endif
30
#endif
31
 
31
 
32
//
32
//
33
//
33
//
34
//
34
//
35
 
35
 
36
 
36
 
37
 
37
 
38
 
38
 
39
UINT64
39
UINT64
40
LShiftU64 (
40
LShiftU64 (
41
    IN UINT64   Operand,
41
    IN UINT64   Operand,
42
    IN UINTN    Count
42
    IN UINTN    Count
43
    )
43
    )
44
// Left shift 64bit by 32bit and get a 64bit result
44
// Left shift 64bit by 32bit and get a 64bit result
45
{
45
{
46
    return Operand << Count;
46
    return Operand << Count;
47
}
47
}
48
 
48
 
49
UINT64
49
UINT64
50
RShiftU64 (
50
RShiftU64 (
51
    IN UINT64   Operand,
51
    IN UINT64   Operand,
52
    IN UINTN    Count
52
    IN UINTN    Count
53
    )
53
    )
54
// Right shift 64bit by 32bit and get a 64bit result
54
// Right shift 64bit by 32bit and get a 64bit result
55
{
55
{
56
    return Operand >> Count;
56
    return Operand >> Count;
57
}
57
}
58
 
58
 
59
 
59
 
60
UINT64
60
UINT64
61
MultU64x32 (
61
MultU64x32 (
62
    IN UINT64   Multiplicand,
62
    IN UINT64   Multiplicand,
63
    IN UINTN    Multiplier
63
    IN UINTN    Multiplier
64
    )
64
    )
65
// Multiple 64bit by 32bit and get a 64bit result
65
// Multiple 64bit by 32bit and get a 64bit result
66
{
66
{
67
    return Multiplicand * Multiplier;
67
    return Multiplicand * Multiplier;
68
}
68
}
69
 
69
 
70
UINT64
70
UINT64
71
DivU64x32 (
71
DivU64x32 (
72
    IN UINT64   Dividend,
72
    IN UINT64   Dividend,
73
    IN UINTN    Divisor,
73
    IN UINTN    Divisor,
74
    OUT UINTN   *Remainder OPTIONAL
74
    OUT UINTN   *Remainder OPTIONAL
75
    )
75
    )
76
// divide 64bit by 32bit and get a 64bit result
76
// divide 64bit by 32bit and get a 64bit result
77
// N.B. only works for 31bit divisors!!
77
// N.B. only works for 31bit divisors!!
78
{
78
{
79
    ASSERT (Divisor != 0);
79
    ASSERT (Divisor != 0);
80
 
80
 
81
    if (Remainder) {
81
    if (Remainder) {
82
        *Remainder = Dividend % Divisor;
82
        *Remainder = Dividend % Divisor;
83
    }
83
    }
84
 
84
 
85
    return Dividend / Divisor;
85
    return Dividend / Divisor;
86
}
86
}
87
 
87