aboutsummaryrefslogtreecommitdiff
path: root/src/vm_arm.dasc
diff options
context:
space:
mode:
authorMike Pall <mike>2025-11-27 17:45:17 +0100
committerMike Pall <mike>2025-11-27 17:45:17 +0100
commitf80b349d5490aa289b2925d297f3f3c618977570 (patch)
tree8d8fb0d2beb3e863592139d603ada63e5aa6ce77 /src/vm_arm.dasc
parent3215838aa744d148e79a8ea0bd7c014e984302cb (diff)
downloadluajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.gz
luajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.bz2
luajit-f80b349d5490aa289b2925d297f3f3c618977570.zip
Unify Lua number to FFI integer conversions.
Phew. #1411
Diffstat (limited to 'src/vm_arm.dasc')
-rw-r--r--src/vm_arm.dasc115
1 files changed, 114 insertions, 1 deletions
diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc
index 86bef0cf..2cd7eedb 100644
--- a/src/vm_arm.dasc
+++ b/src/vm_arm.dasc
@@ -2452,6 +2452,118 @@ static void build_subroutines(BuildCtx *ctx)
2452 | bx lr 2452 | bx lr
2453 | 2453 |
2454 |//----------------------------------------------------------------------- 2454 |//-----------------------------------------------------------------------
2455 |//-- Number conversion functions ----------------------------------------
2456 |//-----------------------------------------------------------------------
2457 |
2458 |// int64_t lj_vm_num2int_check(double x)
2459 |->vm_num2int_check:
2460 |.if FPU
2461 |.if not HFABI
2462 | vmov d0, CARG1, CARG2
2463 |.endif
2464 | vcvt.s32.f64 s4, d0
2465 | vcvt.f64.s32 d1, s4
2466 | vcmp.f64 d0, d1
2467 | vmrs
2468 | bne >1
2469 | vmov CRET1, s4
2470 | mov CRET2, #0
2471 | bx lr
2472 |
2473 |.else
2474 |
2475 | asr CARG4, CARG2, #31 // sign = 0 or -1.
2476 | lsl CARG2, CARG2, #1
2477 | orrs RB, CARG2, CARG1
2478 | bxeq lr // Return 0 for +-0.
2479 | mov RB, #1024
2480 | add RB, RB, #30
2481 | sub RB, RB, CARG2, lsr #21
2482 | cmp RB, #32
2483 | bhs >1 // Fail if |x| < 0x1p0 || |x| >= 0x1p32.
2484 | lsr CARG3, CARG1, #21
2485 | orr CARG2, CARG3, CARG2, lsl #10 // Left-aligned mantissa.
2486 | rsb CARG3, RB, #32
2487 | lsl CARG3, CARG2, CARG3
2488 | orr CARG2, CARG2, #0x80000000 // Merge leading 1.
2489 | orrs CARG3, CARG3, CARG1, lsl #11
2490 | lsr CARG1, CARG2, RB // lo = right-aligned absolute value.
2491 | bne >1 // Fail if fractional part != 0.
2492 | adds CRET1, CARG1, CARG4
2493 | bmi >1 // Fail if lo+sign >= 0x80000000.
2494 | eor CRET1, CRET1, CARG4 // lo = sign?-lo:lo = (lo+sign)^sign.
2495 | mov CRET2, #0
2496 | bx lr
2497 |.endif
2498 |1:
2499 | mov CRET1, #0x80000000
2500 | mov CRET2, #0x80000000
2501 | bx lr
2502 |
2503 |// int64_t lj_vm_num2i64(double x)
2504 |->vm_num2i64:
2505 |// fallthrough, same as lj_vm_num2u64.
2506 |
2507 |// uint64_t lj_vm_num2u64(double x)
2508 |->vm_num2u64:
2509 |.if HFABI
2510 | vmov CARG1, CARG2, d0
2511 |.endif
2512 | lsl RB, CARG2, #1
2513 | lsr RB, RB, #21
2514 | sub RB, RB, #1020
2515 | sub RB, RB, #3
2516 | cmp RB, #116
2517 | bhs >3 // Exponent out of range.
2518 | asr CARG4, CARG2, #31 // sign = 0 or -1.
2519 | lsl CARG2, CARG2, #12
2520 | lsr CARG2, CARG2, #12
2521 | rsbs RB, RB, #52
2522 | orr CARG2, CARG2, #0x00100000
2523 | bmi >2 // Shift mantissa left or right?
2524 | lsr CARG1, CARG1, RB // 64 bit right shift.
2525 | lsr CARG3, CARG2, RB
2526 | rsb RB, RB, #32
2527 | orr CARG1, CARG1, CARG2, lsl RB
2528 | rsb RB, RB, #0
2529 | orr CARG1, CARG1, CARG2, lsr RB
2530 | adds CRET1, CARG1, CARG4 // m = sign?-m:m = (m+sign)^sign.
2531 | adc CRET2, CARG3, CARG4
2532 |1:
2533 | eor CRET1, CRET1, CARG4
2534 | eor CRET2, CRET2, CARG4
2535 | bx lr
2536 |2:
2537 | rsb RB, RB, #0
2538 | lsl CARG2, CARG2, RB // 64 bit left shift.
2539 | lsl CARG3, CARG1, RB
2540 | sub RB, RB, #32
2541 | orr CARG2, CARG2, CARG1, lsl RB
2542 | rsb RB, RB, #0
2543 | orr CARG2, CARG2, CARG1, lsr RB
2544 | adds CRET1, CARG3, CARG4
2545 | adc CRET2, CARG2, CARG4
2546 | b <1
2547 |3:
2548 | mov CRET1, #0
2549 | mov CRET2, #0
2550 | bx lr
2551 |
2552 |// int32_t lj_vm_tobit(double x)
2553 |.if FPU
2554 |->vm_tobit:
2555 | vldr d1, >9
2556 |.if not HFABI
2557 | vmov d0, CARG1, CARG2
2558 |.endif
2559 | vadd.f64 d0, d0, d1
2560 | vmov CARG1, s0
2561 | bx lr
2562 |9:
2563 | .long 0, 0x43380000 // (double)(2^52 + 2^51).
2564 |.endif
2565 |
2566 |//-----------------------------------------------------------------------
2455 |//-- Miscellaneous functions -------------------------------------------- 2567 |//-- Miscellaneous functions --------------------------------------------
2456 |//----------------------------------------------------------------------- 2568 |//-----------------------------------------------------------------------
2457 | 2569 |
@@ -4097,7 +4209,8 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
4097 | ldr TRACE:CARG1, [CARG1, CARG2, lsl #2] 4209 | ldr TRACE:CARG1, [CARG1, CARG2, lsl #2]
4098 | // Subsumes ins_next1 and ins_next2. 4210 | // Subsumes ins_next1 and ins_next2.
4099 | ldr INS, TRACE:CARG1->startins 4211 | ldr INS, TRACE:CARG1->startins
4100 | bfi INS, OP, #0, #8 4212 | bic INS, INS, #0xff
4213 | orr INS, INS, OP
4101 | str INS, [PC], #4 4214 | str INS, [PC], #4
4102 | b <1 4215 | b <1
4103 |.endif 4216 |.endif