1706f2543Smrg/*
2706f2543Smrg * Copyright (C) 2000 The XFree86 Project, Inc.  All Rights Reserved.
3706f2543Smrg *
4706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a copy
5706f2543Smrg * of this software and associated documentation files (the "Software"), to
6706f2543Smrg * deal in the Software without restriction, including without limitation the
7706f2543Smrg * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8706f2543Smrg * sell copies of the Software, and to permit persons to whom the Software is
9706f2543Smrg * furnished to do so, subject to the following conditions:
10706f2543Smrg *
11706f2543Smrg * The above copyright notice and this permission notice shall be included in
12706f2543Smrg * all copies or substantial portions of the Software.
13706f2543Smrg *
14706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17706f2543Smrg * XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18706f2543Smrg * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19706f2543Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20706f2543Smrg *
21706f2543Smrg * Except as contained in this notice, the name of the XFree86 Project shall
22706f2543Smrg * not be used in advertising or otherwise to promote the sale, use or other
23706f2543Smrg * dealings in this Software without prior written authorization from the
24706f2543Smrg * XFree86 Project.
25706f2543Smrg *
26706f2543Smrg */
27706f2543Smrg
28706f2543Smrg#ifndef _MICOORD_H_
29706f2543Smrg#define _MICOORD_H_ 1
30706f2543Smrg
31706f2543Smrg#include "servermd.h"
32706f2543Smrg
33706f2543Smrg/* Macros which handle a coordinate in a single register */
34706f2543Smrg
35706f2543Smrg/*
36706f2543Smrg * Most compilers will convert divisions by 65536 into shifts, if signed
37706f2543Smrg * shifts exist.  If your machine does arithmetic shifts and your compiler
38706f2543Smrg * can't get it right, add to this line.
39706f2543Smrg */
40706f2543Smrg
41706f2543Smrg/*
42706f2543Smrg * mips compiler - what a joke - it CSEs the 65536 constant into a reg
43706f2543Smrg * forcing as to use div instead of shift.  Let's be explicit.
44706f2543Smrg */
45706f2543Smrg
46706f2543Smrg#if defined(mips) || \
47706f2543Smrg    defined(sparc) || defined(__sparc64__) || \
48706f2543Smrg    defined(__alpha) || defined(__alpha__) || \
49706f2543Smrg    defined(__i386__) || defined(__i386) || defined(__ia64__) || \
50706f2543Smrg    defined(__s390x__) || defined(__s390__) || \
51706f2543Smrg    defined(__amd64__) || defined(amd64) || defined(__amd64)
52706f2543Smrg#define GetHighWord(x) (((int) (x)) >> 16)
53706f2543Smrg#else
54706f2543Smrg#define GetHighWord(x) (((int) (x)) / 65536)
55706f2543Smrg#endif
56706f2543Smrg
57706f2543Smrg#if IMAGE_BYTE_ORDER == MSBFirst
58706f2543Smrg#define intToCoord(i,x,y)   (((x) = GetHighWord(i)), ((y) = (int) ((short) (i))))
59706f2543Smrg#define coordToInt(x,y)	(((x) << 16) | ((y) & 0xffff))
60706f2543Smrg#define intToX(i)	(GetHighWord(i))
61706f2543Smrg#define intToY(i)	((int) ((short) i))
62706f2543Smrg#else
63706f2543Smrg#define intToCoord(i,x,y)   (((x) = (int) ((short) (i))), ((y) = GetHighWord(i)))
64706f2543Smrg#define coordToInt(x,y)	(((y) << 16) | ((x) & 0xffff))
65706f2543Smrg#define intToX(i)	((int) ((short) (i)))
66706f2543Smrg#define intToY(i)	(GetHighWord(i))
67706f2543Smrg#endif
68706f2543Smrg
69706f2543Smrg#endif /* _MICOORD_H_ */
70