diff options
| author | Mike Pall <mike> | 2011-04-17 02:31:00 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-04-17 02:31:00 +0200 |
| commit | 7bb4b0f57082bec83b1048a379f1eb1ca28b0b44 (patch) | |
| tree | af3db8fc769df999351e7229f37a04e6b4395201 /src | |
| parent | 32db4525d9e02aba29cf393025afcb1febff8458 (diff) | |
| download | luajit-7bb4b0f57082bec83b1048a379f1eb1ca28b0b44.tar.gz luajit-7bb4b0f57082bec83b1048a379f1eb1ca28b0b44.tar.bz2 luajit-7bb4b0f57082bec83b1048a379f1eb1ca28b0b44.zip | |
ARM: Normalize results of math.floor()/ceil() fast functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buildvm_arm.dasc | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/src/buildvm_arm.dasc b/src/buildvm_arm.dasc index 905e0ada..68f33d97 100644 --- a/src/buildvm_arm.dasc +++ b/src/buildvm_arm.dasc | |||
| @@ -1203,8 +1203,74 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1203 | | | 1203 | | |
| 1204 | |//-- Math library ------------------------------------------------------- | 1204 | |//-- Math library ------------------------------------------------------- |
| 1205 | | | 1205 | | |
| 1206 | |.align 8 | 1206 | |.macro math_round, func |
| 1207 | | .ffunc_1 math_ .. func | ||
| 1208 | | checktp CARG2, LJ_TISNUM | ||
| 1209 | | beq ->fff_restv | ||
| 1210 | | bhi ->fff_fallback | ||
| 1211 | | // Round FP value and normalize result. | ||
| 1212 | | lsl CARG3, CARG2, #1 | ||
| 1213 | | adds RB, CARG3, #0x00200000 | ||
| 1214 | | bpl >2 // |x| < 1? | ||
| 1215 | | mvn CARG4, #0x3e0 | ||
| 1216 | | subs RB, CARG4, RB, asr #21 | ||
| 1217 | | lsl CARG4, CARG2, #11 | ||
| 1218 | | lsl CARG3, CARG1, #11 | ||
| 1219 | | orr CARG4, CARG4, #0x80000000 | ||
| 1220 | | rsb INS, RB, #32 | ||
| 1221 | | orr CARG4, CARG4, CARG1, lsr #21 | ||
| 1222 | | bls >3 // |x| >= 2^31? | ||
| 1223 | | orr CARG3, CARG3, CARG4, lsl INS | ||
| 1224 | | lsr CARG1, CARG4, RB | ||
| 1225 | |.if "func" == "floor" | ||
| 1226 | | tst CARG3, CARG2, asr #31 | ||
| 1227 | | addne CARG1, CARG1, #1 | ||
| 1228 | |.else | ||
| 1229 | | bics CARG3, CARG3, CARG2, asr #31 | ||
| 1230 | | addsne CARG1, CARG1, #1 | ||
| 1231 | | ldrdvs CARG12, >9 | ||
| 1232 | | bvs ->fff_restv | ||
| 1233 | |.endif | ||
| 1234 | | cmp CARG2, #0 | ||
| 1235 | | rsblt CARG1, CARG1, #0 | ||
| 1207 | |1: | 1236 | |1: |
| 1237 | | mvn CARG2, #~LJ_TISNUM | ||
| 1238 | | b ->fff_restv | ||
| 1239 | | | ||
| 1240 | |2: // |x| < 1 | ||
| 1241 | | orr CARG3, CARG3, CARG1 // ztest = abs(hi) | lo | ||
| 1242 | |.if "func" == "floor" | ||
| 1243 | | tst CARG3, CARG2, asr #31 // return (ztest & sign) == 0 ? 0 : -1 | ||
| 1244 | | moveq CARG1, #0 | ||
| 1245 | | mvnne CARG1, #0 | ||
| 1246 | |.else | ||
| 1247 | | bics CARG3, CARG3, CARG2, asr #31 // return (ztest & ~sign) == 0 ? 0 : 1 | ||
| 1248 | | moveq CARG1, #0 | ||
| 1249 | | movne CARG1, #1 | ||
| 1250 | |.endif | ||
| 1251 | | mvn CARG2, #~LJ_TISNUM | ||
| 1252 | | b ->fff_restv | ||
| 1253 | | | ||
| 1254 | |3: // |x| >= 2^31. Check for x == -(2^31). | ||
| 1255 | | cmpeq CARG4, #0x80000000 | ||
| 1256 | |.if "func" == "floor" | ||
| 1257 | | cmpeq CARG3, #0 | ||
| 1258 | |.endif | ||
| 1259 | | bne >4 | ||
| 1260 | | cmp CARG2, #0 | ||
| 1261 | | movmi CARG1, #0x80000000 | ||
| 1262 | | bmi <1 | ||
| 1263 | |4: | ||
| 1264 | | // NYI: Use internal implementation. | ||
| 1265 | | bl extern func | ||
| 1266 | | b ->fff_restv | ||
| 1267 | |.endmacro | ||
| 1268 | | | ||
| 1269 | | math_round floor | ||
| 1270 | | math_round ceil | ||
| 1271 | | | ||
| 1272 | |.align 8 | ||
| 1273 | |9: | ||
| 1208 | | .long 0x00000000, 0x41e00000 // 2^31. | 1274 | | .long 0x00000000, 0x41e00000 // 2^31. |
| 1209 | | | 1275 | | |
| 1210 | |.ffunc_1 math_abs | 1276 | |.ffunc_1 math_abs |
| @@ -1214,7 +1280,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1214 | | bne ->fff_restv | 1280 | | bne ->fff_restv |
| 1215 | | cmp CARG1, #0 | 1281 | | cmp CARG1, #0 |
| 1216 | | rsbslt CARG1, CARG1, #0 | 1282 | | rsbslt CARG1, CARG1, #0 |
| 1217 | | ldrdvs CARG12, <1 | 1283 | | ldrdvs CARG12, <9 |
| 1218 | | // Fallthrough. | 1284 | | // Fallthrough. |
| 1219 | | | 1285 | | |
| 1220 | |->fff_restv: | 1286 | |->fff_restv: |
| @@ -1261,18 +1327,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1261 | | b ->fff_restv | 1327 | | b ->fff_restv |
| 1262 | |.endmacro | 1328 | |.endmacro |
| 1263 | | | 1329 | | |
| 1264 | |.macro math_round, func | ||
| 1265 | | .ffunc_1 math_ .. func | ||
| 1266 | | checktp CARG2, LJ_TISNUM | ||
| 1267 | | bhi ->fff_fallback | ||
| 1268 | | bllo extern func // NYI: use internal implementation of floor/ceil. | ||
| 1269 | | // NYI: normalize result. | ||
| 1270 | | b ->fff_restv | ||
| 1271 | |.endmacro | ||
| 1272 | | | ||
| 1273 | | math_round floor | ||
| 1274 | | math_round ceil | ||
| 1275 | | | ||
| 1276 | | math_extern sqrt | 1330 | | math_extern sqrt |
| 1277 | | math_extern log | 1331 | | math_extern log |
| 1278 | | math_extern log10 | 1332 | | math_extern log10 |
| @@ -1805,18 +1859,18 @@ static void build_subroutines(BuildCtx *ctx) | |||
| 1805 | |//-- Math helper functions ---------------------------------------------- | 1859 | |//-- Math helper functions ---------------------------------------------- |
| 1806 | |//----------------------------------------------------------------------- | 1860 | |//----------------------------------------------------------------------- |
| 1807 | | | 1861 | | |
| 1808 | |// FP value rounding. Called by math.floor/math.ceil fast functions | 1862 | |// FP value rounding. Called from JIT code. |
| 1809 | |// and from JIT code. | ||
| 1810 | |// | 1863 | |// |
| 1811 | |.macro vm_round, name, mode | 1864 | |// double lj_vm_floor/ceil/trunc(double x); |
| 1812 | |->name: | 1865 | |.macro vm_round, func |
| 1866 | |->vm_ .. func: | ||
| 1813 | | NYI | 1867 | | NYI |
| 1814 | |.endmacro | 1868 | |.endmacro |
| 1815 | | | 1869 | | |
| 1816 | | vm_round vm_floor, 0 | 1870 | | vm_round floor |
| 1817 | | vm_round vm_ceil, 1 | 1871 | | vm_round ceil |
| 1818 | #if LJ_HASJIT | 1872 | #if LJ_HASJIT |
| 1819 | | vm_round vm_trunc, 2 | 1873 | | vm_round trunc |
| 1820 | #else | 1874 | #else |
| 1821 | |->vm_trunc: | 1875 | |->vm_trunc: |
| 1822 | #endif | 1876 | #endif |
