Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / ps / math.c
1 /* $Id$
2  * long-value math emulation for support of ntoskrnl of libcaptive
3  * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "reactos/ntos/types.h"
23 #include <glib/gmessages.h>
24
25
26 /**
27  * _allmul:
28  * @a: First #LONGLONG multiplier.
29  * @b: Second #LONGLONG multiplier.
30  *
31  * Returns: @a * @b. No overflows are checked.
32  */
33 LONGLONG _allmul(LONGLONG a,LONGLONG b)
34 {
35         return a*b;
36 }
37
38
39 /**
40  * _alldiv:
41  * @a: #LONGLONG divisor.
42  * @b: #LONGLONG divider.
43  * Value %0 is forbidden.
44  *
45  * Returns: @a / @b.
46  */
47 LONGLONG _alldiv(LONGLONG a,LONGLONG b)
48 {
49         g_return_val_if_fail(b!=0,0);
50
51         return a/b;
52 }
53
54
55 /**
56  * _allshl:
57  * @long_00to31: Lower part of 64-bit unsigned number to shift.
58  * @long_32to63: Upper part of 64-bit unsigned number to shift.
59  * @count: Number of bits to shift by.
60  *
61  * 64-bit shift left by @count bits.
62  *
63  * This is a special function which is declared as %data in *.def
64  * file ke/exports.def as it has three arguments passed in registers.
65  *
66  * Returns: (@long_32to63 @long_00to31) shifted left by @count bits.
67  */
68 guint64 __attribute__((__stdcall__)) __attribute__((__regparm__(3))) _allshl(
69                 guint32 long_00to31,    /* %eax */
70                 guint32 long_32to63,    /* %edx */
71                 guint8  count)  /* %ecx */
72 {
73         return (((((guint64)long_32to63)<<32U)|long_00to31)<<count);
74 }
75
76
77 /**
78  * _allshr:
79  * @long_00to31: Lower part of 64-bit signed number to shift.
80  * @long_32to63: Upper part of 64-bit signed number to shift.
81  * @count: Number of bits to shift by.
82  *
83  * 64-bit shift right by @count bits.
84  *
85  * WARNING: Although this function is call _allshr() it in fact implements
86  * instruction %sar, NOT %shr!
87  *
88  * This is a special function which is declared as %data in *.def
89  * file ke/exports.def as it has three arguments passed in registers.
90  *
91  * Returns: (@long_32to63 @long_00to31) signed-shifted right by @count bits.
92  */
93 guint64 __attribute__((__stdcall__)) __attribute__((__regparm__(3))) _allshr(
94                 guint32 long_00to31,    /* %eax */
95                 guint32 long_32to63,    /* %edx */
96                 guint8  count)  /* %ecx */
97 {
98         return (((((gint64)long_32to63)<<32U)|long_00to31)>>count);
99 }
100
101
102 /**
103  * _aullshr:
104  * @long_00to31: Lower part of 64-bit unsigned number to shift.
105  * @long_32to63: Upper part of 64-bit unsigned number to shift.
106  * @count: Number of bits to shift by.
107  *
108  * 64-bit shift right by @count bits.
109  *
110  * This is a special function which is declared as %data in *.def
111  * file ke/exports.def as it has three arguments passed in registers.
112  *
113  * Returns: (@long_32to63 @long_00to31) unsigned-shifted right by @count bits.
114  */
115 guint64 __attribute__((__stdcall__)) __attribute__((__regparm__(3))) _aullshr(
116                 guint32 long_00to31,    /* %eax */
117                 guint32 long_32to63,    /* %edx */
118                 guint8  count)  /* %ecx */
119 {
120         return (((((guint64)long_32to63)<<32U)|long_00to31)>>count);
121 }
122
123
124 /**
125  * _allrem:
126  * @divident: 64-bit signed divident.
127  * @divisor: 64-bit signed divisor.
128  *
129  * Calculates the signed modulo of two 64-bit numbers.
130  *
131  * FIXME: Are we expected to behave signed?
132  *
133  * Returns: Expression "divident%divisor".
134  */
135 gint64 _allrem(gint64 divident,gint64 divisor)
136 {
137         return divident%divisor;
138 }