Subversion Repositories HelenOS

Rev

Rev 2726 | Details | Compare with Previous | Last modification | View Log | RSS feed

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