comparison graal/com.oracle.jvmci.asm/src/com/oracle/jvmci/asm/NumUtil.java @ 21708:6df25b1418be

moved com.oracle.asm.** to jvmci-util.jar (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 03 Jun 2015 18:06:44 +0200
parents graal/com.oracle.graal.asm/src/com/oracle/graal/asm/NumUtil.java@feca840a7d81
children
comparison
equal deleted inserted replaced
21707:e0f311284930 21708:6df25b1418be
1 /*
2 * Copyright (c) 2011, 2013, 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.jvmci.asm;
24
25 // JaCoCo Exclude
26
27 /**
28 * A collection of static utility functions that check ranges of numbers.
29 */
30 public class NumUtil {
31
32 public static boolean isShiftCount(int x) {
33 return 0 <= x && x < 32;
34 }
35
36 /**
37 * Determines if a given {@code int} value is the range of unsigned byte values.
38 */
39 public static boolean isUByte(int x) {
40 return (x & 0xff) == x;
41 }
42
43 /**
44 * Determines if a given {@code int} value is the range of signed byte values.
45 */
46 public static boolean isByte(int x) {
47 return (byte) x == x;
48 }
49
50 /**
51 * Determines if a given {@code long} value is the range of unsigned byte 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 values.
59 */
60 public static boolean isByte(long l) {
61 return (byte) l == l;
62 }
63
64 /**
65 * Determines if a given {@code long} value is the range of unsigned int values.
66 */
67 public static boolean isUInt(long x) {
68 return (x & 0xffffffffL) == x;
69 }
70
71 /**
72 * Determines if a given {@code long} value is the range of signed int values.
73 */
74 public static boolean isInt(long l) {
75 return (int) l == l;
76 }
77
78 /**
79 * Determines if a given {@code int} value is the range of signed short values.
80 */
81 public static boolean isShort(int x) {
82 return (short) x == x;
83 }
84
85 /**
86 * Determines if a given {@code long} value is the range of signed short values.
87 */
88 public static boolean isShort(long x) {
89 return (short) x == x;
90 }
91
92 public static boolean isUShort(int s) {
93 return s == (s & 0xFFFF);
94 }
95
96 public static boolean is32bit(long x) {
97 return -0x80000000L <= x && x < 0x80000000L;
98 }
99
100 public static short safeToShort(int v) {
101 assert isShort(v);
102 return (short) v;
103 }
104
105 public static int roundUp(int number, int mod) {
106 return ((number + mod - 1) / mod) * mod;
107 }
108
109 public static long roundUp(long number, long mod) {
110 return ((number + mod - 1L) / mod) * mod;
111 }
112 }