blob: 298cef1805f089a75f574bdaa4921207e869775d [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
buzbee1b4c8592011-08-31 10:43:51 -070020namespace art {
buzbee67bf8852011-08-17 17:51:35 -070021/* FIXME - codegen helper functions, move to art runtime proper */
22
23/*
24 * Float/double conversion requires clamping to min and max of integer form. If
25 * target doesn't support this normally, use these.
26 */
buzbee1b4c8592011-08-31 10:43:51 -070027int64_t D2L(double d)
buzbee67bf8852011-08-17 17:51:35 -070028{
29 static const double kMaxLong = (double)(s8)0x7fffffffffffffffULL;
30 static const double kMinLong = (double)(s8)0x8000000000000000ULL;
31 if (d >= kMaxLong)
32 return (s8)0x7fffffffffffffffULL;
33 else if (d <= kMinLong)
34 return (s8)0x8000000000000000ULL;
35 else if (d != d) // NaN case
36 return 0;
37 else
38 return (s8)d;
39}
40
buzbee1b4c8592011-08-31 10:43:51 -070041int64_t F2L(float f)
buzbee67bf8852011-08-17 17:51:35 -070042{
43 static const float kMaxLong = (float)(s8)0x7fffffffffffffffULL;
44 static const float kMinLong = (float)(s8)0x8000000000000000ULL;
45 if (f >= kMaxLong)
46 return (s8)0x7fffffffffffffffULL;
47 else if (f <= kMinLong)
48 return (s8)0x8000000000000000ULL;
49 else if (f != f) // NaN case
50 return 0;
51 else
52 return (s8)f;
53}
buzbeee6d61962011-08-27 11:58:19 -070054
55/*
56 * Temporary placeholder. Should include run-time checks for size
57 * of fill data <= size of array. If not, throw arrayOutOfBoundsException.
buzbee1b4c8592011-08-31 10:43:51 -070058 * As with other new "FromCode" routines, this should return to the caller
buzbeee6d61962011-08-27 11:58:19 -070059 * only if no exception has been thrown.
60 *
61 * NOTE: When dealing with a raw dex file, the data to be copied uses
62 * little-endian ordering. Require that oat2dex do any required swapping
63 * so this routine can get by with a memcpy().
64 *
65 * Format of the data:
66 * ushort ident = 0x0300 magic value
67 * ushort width width of each element in the table
68 * uint size number of elements in the table
69 * ubyte data[size*width] table of data values (may contain a single-byte
70 * padding at the end)
71 */
buzbee1b4c8592011-08-31 10:43:51 -070072void HandleFillArrayDataFromCode(Array* array, const uint16_t* table)
buzbeee6d61962011-08-27 11:58:19 -070073{
74 uint32_t size = (uint32_t)table[2] | (((uint32_t)table[3]) << 16);
75 uint32_t size_in_bytes = size * table[1];
76 UNIMPLEMENTED(WARNING) << "Need to check if array.length() <= size";
77 memcpy((char*)array + art::Array::DataOffset().Int32Value(),
78 (char*)&table[4], size_in_bytes);
79}
buzbee1b4c8592011-08-31 10:43:51 -070080
81} // namespace art