Mercurial > hg > graal-compiler
comparison graal/com.oracle.graal.asm/src/com/oracle/max/asm/NumUtil.java @ 6497:64b7dd2075c0
renamed projects com.oracle.max.asm* to com.oracle.graal.asm*
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 03 Oct 2012 17:42:12 +0200 |
parents | graal/com.oracle.max.asm/src/com/oracle/max/asm/NumUtil.java@681e969888a7 |
children |
comparison
equal
deleted
inserted
replaced
6496:16d1411409b4 | 6497:64b7dd2075c0 |
---|---|
1 /* | |
2 * Copyright (c) 2011, 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.max.asm; | |
24 | |
25 /** | |
26 * A collection of static utility functions that check ranges of numbers. | |
27 */ | |
28 public class NumUtil { | |
29 public static boolean isShiftCount(int x) { | |
30 return 0 <= x && x < 32; | |
31 } | |
32 | |
33 /** | |
34 * Determines if a given {@code int} value is the range of unsigned byte | |
35 * values. | |
36 */ | |
37 public static boolean isUByte(int x) { | |
38 return (x & 0xff) == x; | |
39 } | |
40 | |
41 /** | |
42 * Determines if a given {@code int} value is the range of signed byte | |
43 * values. | |
44 */ | |
45 public static boolean isByte(int x) { | |
46 return (byte) x == x; | |
47 } | |
48 | |
49 /** | |
50 * Determines if a given {@code long} value is the range of unsigned byte | |
51 * values. | |
52 */ | |
53 public static boolean isUByte(long x) { | |
54 return (x & 0xffL) == x; | |
55 } | |
56 | |
57 /** | |
58 * Determines if a given {@code long} value is the range of signed byte | |
59 * values. | |
60 */ | |
61 public static boolean isByte(long l) { | |
62 return (byte) l == l; | |
63 } | |
64 | |
65 /** | |
66 * Determines if a given {@code long} value is the range of unsigned int | |
67 * values. | |
68 */ | |
69 public static boolean isUInt(long x) { | |
70 return (x & 0xffffffffL) == x; | |
71 } | |
72 | |
73 /** | |
74 * Determines if a given {@code long} value is the range of signed int | |
75 * values. | |
76 */ | |
77 public static boolean isInt(long l) { | |
78 return (int) l == l; | |
79 } | |
80 | |
81 /** | |
82 * Determines if a given {@code int} value is the range of signed short | |
83 * values. | |
84 */ | |
85 public static boolean isShort(int x) { | |
86 return (short) x == x; | |
87 } | |
88 | |
89 public static boolean isUShort(int s) { | |
90 return s == (s & 0xFFFF); | |
91 } | |
92 | |
93 public static boolean is32bit(long x) { | |
94 return -0x80000000L <= x && x < 0x80000000L; | |
95 } | |
96 | |
97 public static short safeToShort(int v) { | |
98 assert isShort(v); | |
99 return (short) v; | |
100 } | |
101 | |
102 public static int roundUp(int number, int mod) { | |
103 return ((number + mod - 1) / mod) * mod; | |
104 } | |
105 } |