blob: 53bd20e008d79a1ef1ddb77265a79f7825e29d8c [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "Dalvik.h"
18#include "CompilerInternals.h"
19
20/* FIXME - codegen helper functions, move to art runtime proper */
21
22/*
23 * Float/double conversion requires clamping to min and max of integer form. If
24 * target doesn't support this normally, use these.
25 */
buzbee7b1b86d2011-08-26 18:59:10 -070026int64_t artD2L(double d)
buzbee67bf8852011-08-17 17:51:35 -070027{
28 static const double kMaxLong = (double)(s8)0x7fffffffffffffffULL;
29 static const double kMinLong = (double)(s8)0x8000000000000000ULL;
30 if (d >= kMaxLong)
31 return (s8)0x7fffffffffffffffULL;
32 else if (d <= kMinLong)
33 return (s8)0x8000000000000000ULL;
34 else if (d != d) // NaN case
35 return 0;
36 else
37 return (s8)d;
38}
39
buzbee7b1b86d2011-08-26 18:59:10 -070040int64_t artF2L(float f)
buzbee67bf8852011-08-17 17:51:35 -070041{
42 static const float kMaxLong = (float)(s8)0x7fffffffffffffffULL;
43 static const float kMinLong = (float)(s8)0x8000000000000000ULL;
44 if (f >= kMaxLong)
45 return (s8)0x7fffffffffffffffULL;
46 else if (f <= kMinLong)
47 return (s8)0x8000000000000000ULL;
48 else if (f != f) // NaN case
49 return 0;
50 else
51 return (s8)f;
52}
buzbeee6d61962011-08-27 11:58:19 -070053
54/*
55 * Temporary placeholder. Should include run-time checks for size
56 * of fill data <= size of array. If not, throw arrayOutOfBoundsException.
57 * As with other new "NoThrow" routines, this should return to the caller
58 * only if no exception has been thrown.
59 *
60 * NOTE: When dealing with a raw dex file, the data to be copied uses
61 * little-endian ordering. Require that oat2dex do any required swapping
62 * so this routine can get by with a memcpy().
63 *
64 * Format of the data:
65 * ushort ident = 0x0300 magic value
66 * ushort width width of each element in the table
67 * uint size number of elements in the table
68 * ubyte data[size*width] table of data values (may contain a single-byte
69 * padding at the end)
70 */
71void artHandleFillArrayDataNoThrow(Array* array, const uint16_t* table)
72{
73 uint32_t size = (uint32_t)table[2] | (((uint32_t)table[3]) << 16);
74 uint32_t size_in_bytes = size * table[1];
75 UNIMPLEMENTED(WARNING) << "Need to check if array.length() <= size";
76 memcpy((char*)array + art::Array::DataOffset().Int32Value(),
77 (char*)&table[4], size_in_bytes);
78}