blob: d40f09748009f50ffb9465623e8472a21f63302f [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 */
26s8 artD2L(double d)
27{
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
40s8 artF2L(float f)
41{
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}