Browse Source

slightly reduce code size

ipatix 7 years ago
parent
commit
795224bff1
1 changed files with 9 additions and 10 deletions
  1. 9
    10
      src/music/main_mixer.s

+ 9
- 10
src/music/main_mixer.s View File

512
         ADD     R10, R10, R0
512
         ADD     R10, R10, R0
513
         CMP     R10, SP
513
         CMP     R10, SP
514
         ADD     R10, R3, R0
514
         ADD     R10, R3, R0
515
-        ADR     R9, stack_backup
516
         /*
515
         /*
517
          * R2 = remaining samples after processing
516
          * R2 = remaining samples after processing
518
          * R10 = final sample position
517
          * R10 = final sample position
520
          * These values will get reloaded after channel processing
519
          * These values will get reloaded after channel processing
521
          * due to the lack of registers.
520
          * due to the lack of registers.
522
          */
521
          */
523
-        STMIA   R9, {R2, R10, SP}
522
+        STMFD   SP!, {R2, R10}
524
         CMPCC   R0, #0x400                      @ > 0x400 bytes --> read directly from ROM rather than buffered
523
         CMPCC   R0, #0x400                      @ > 0x400 bytes --> read directly from ROM rather than buffered
524
+        MOV     R10, SP
525
         BCS     C_select_highspeed_codepath
525
         BCS     C_select_highspeed_codepath
526
         /*
526
         /*
527
          * The code below inits the DMA to read word aligned
527
          * The code below inits the DMA to read word aligned
547
     .endif
547
     .endif
548
 
548
 
549
 C_select_highspeed_codepath:
549
 C_select_highspeed_codepath:
550
+        STMFD   SP!, {R10}                      @ save original SP for VLA
550
         /*
551
         /*
551
          * This code decides which piece of code to load
552
          * This code decides which piece of code to load
552
          * depending on playback-rate / default-rate ratio.
553
          * depending on playback-rate / default-rate ratio.
587
         MOV     R2, #0xFF000000                 @ load the fine position overflow bitmask
588
         MOV     R2, #0xFF000000                 @ load the fine position overflow bitmask
588
 C_fast_mixing_loop:
589
 C_fast_mixing_loop:
589
         /* This is the actual processing and interpolation code loop; NOPs will be replaced by the code above */
590
         /* This is the actual processing and interpolation code loop; NOPs will be replaced by the code above */
590
-            LDMIA   R5, {R0, R1, R10, LR}         @ load 4 stereo samples to Registers
591
+            LDMIA   R5, {R0, R1, R10, LR}       @ load 4 stereo samples to Registers
591
             MUL     R9, R7, R12
592
             MUL     R9, R7, R12
592
 fast_mixing_instructions:
593
 fast_mixing_instructions:
593
             NOP                                 @ Block #1
594
             NOP                                 @ Block #1
625
             NOP
626
             NOP
626
             NOP
627
             NOP
627
             BIC     R7, R7, R2, ASR#1
628
             BIC     R7, R7, R2, ASR#1
628
-            STMIA   R5!, {R0, R1, R10, LR}        @ write 4 stereo samples
629
+            STMIA   R5!, {R0, R1, R10, LR}      @ write 4 stereo samples
629
 
630
 
630
-            LDMIA   R5, {R0, R1, R10, LR}         @ load the next 4 stereo samples
631
+            LDMIA   R5, {R0, R1, R10, LR}       @ load the next 4 stereo samples
631
             MULNE   R9, R7, R12
632
             MULNE   R9, R7, R12
632
             NOP                                 @ Block #1
633
             NOP                                 @ Block #1
633
             NOP
634
             NOP
668
             SUBS    R8, R8, #8
669
             SUBS    R8, R8, #8
669
             BGT     C_fast_mixing_loop
670
             BGT     C_fast_mixing_loop
670
         /* restore previously saved values */
671
         /* restore previously saved values */
671
-        ADR     R12, stack_backup
672
-        LDMIA   R12, {R2, R3, SP}
672
+        LDMFD   SP, {SP}                        @ reload original stack pointer from VLA
673
+        LDMFD   SP!, {R2, R3}
673
         B       C_end_mixing
674
         B       C_end_mixing
674
 
675
 
675
 /* Various variables for the cached mixer */
676
 /* Various variables for the cached mixer */
676
 
677
 
677
     .align    2
678
     .align    2
678
-stack_backup:
679
-    .word    0x0, 0x0, 0x0
680
 upper_stack_bounds:
679
 upper_stack_bounds:
681
     .word    0x03007910
680
     .word    0x03007910
682
 previous_fast_code:
681
 previous_fast_code:
795
         MOVGT   LR, R8                          @ min(buffer_size, sample_countdown)
794
         MOVGT   LR, R8                          @ min(buffer_size, sample_countdown)
796
         SUB     LR, LR, #1
795
         SUB     LR, LR, #1
797
         MOVS    LR, LR, LSR#2
796
         MOVS    LR, LR, LSR#2
798
-        BEQ     C_fixed_mixing_process_rest  @ <= 3 samples to process
797
+        BEQ     C_fixed_mixing_process_rest     @ <= 3 samples to process
799
 
798
 
800
         SUB     R8, R8, LR, LSL#2               @ subtract the amount of samples we need to process from the buffer length
799
         SUB     R8, R8, LR, LSL#2               @ subtract the amount of samples we need to process from the buffer length
801
         SUB     R2, R2, LR, LSL#2               @ subtract the amount of samples we need to process from the remaining samples
800
         SUB     R2, R2, LR, LSL#2               @ subtract the amount of samples we need to process from the remaining samples