buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 20 | namespace art { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 21 | /* 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 | */ |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 27 | int64_t D2L(double d) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 28 | { |
| 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 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 41 | int64_t F2L(float f) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 42 | { |
| 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 | } |
buzbee | e6d6196 | 2011-08-27 11:58:19 -0700 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Temporary placeholder. Should include run-time checks for size |
| 57 | * of fill data <= size of array. If not, throw arrayOutOfBoundsException. |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 58 | * As with other new "FromCode" routines, this should return to the caller |
buzbee | e6d6196 | 2011-08-27 11:58:19 -0700 | [diff] [blame] | 59 | * 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 | */ |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 72 | void HandleFillArrayDataFromCode(Array* array, const uint16_t* table) |
buzbee | e6d6196 | 2011-08-27 11:58:19 -0700 | [diff] [blame] | 73 | { |
| 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 | } |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 80 | |
| 81 | } // namespace art |