Fix ARM assembler for clang.

Use the C preprocessor because clang doesn't have the GNU .if and
friends. Also use #if/#elif/#error rather than assume that one or other
of SAMPLES_8_BIT and SAMPLES_16_BIT has been defined.

Remove the .func/.endfunc stuff for emitting STABS debug info, which
we've never used and LLVM doesn't support.

Fix one instance of an instruction (LDRSH) where the condition code
needed to be moved to the end.

Bug: http://b/133391830
Test: treehugger
Change-Id: I5542c8e1b521c71ed6bcbfa9df84aef1330e1925
diff --git a/arm-wt-22k/Android.bp b/arm-wt-22k/Android.bp
index 32c32ca..c05443b 100644
--- a/arm-wt-22k/Android.bp
+++ b/arm-wt-22k/Android.bp
@@ -111,22 +111,15 @@
                 // In order to use #include instead of .include
                 "-xassembler-with-cpp",
 
-                "-Wa,--defsym,SAMPLE_RATE_22050=1",
-                "-Wa,--defsym,STEREO_OUTPUT=1",
-                "-Wa,--defsym,FILTER_ENABLED=1",
-                "-Wa,--defsym,SAMPLES_16_BIT=1",
+                "-DSAMPLE_RATE_22050=1",
+                "-DSTEREO_OUTPUT=1",
+                "-DFILTER_ENABLED=1",
+                "-DSAMPLES_16_BIT=1",
             ],
 
             cflags: [
                 "-DNATIVE_EAS_KERNEL",
             ],
-
-            // .s files not ported for Clang assembler yet.
-            clang_asflags: ["-no-integrated-as"],
-        },
-        arm64: {
-            // .s files not ported for Clang assembler yet.
-            clang_asflags: ["-no-integrated-as"],
         },
     },
     sanitize: {
diff --git a/arm-wt-22k/lib_src/ARM-E_filter_gnu.s b/arm-wt-22k/lib_src/ARM-E_filter_gnu.s
index 859d9a4..c4ffd55 100644
--- a/arm-wt-22k/lib_src/ARM-E_filter_gnu.s
+++ b/arm-wt-22k/lib_src/ARM-E_filter_gnu.s
@@ -55,7 +55,6 @@
 @RestoreRegs	RLIST	{r4-r10, pc}

 

 

-	.func	WT_VoiceFilter

 WT_VoiceFilter:

 

 	STMFD	sp!, {r4-r10, lr}

@@ -112,7 +111,7 @@
 

 	MOV		z1, tmp1, ASR #14				@ shift result to low word

 	

-	LDRGTSH	tmp0, [pBuffer, #NEXT_OUTPUT_PCM]	@ fetch next sample

+	LDRSHGT	tmp0, [pBuffer, #NEXT_OUTPUT_PCM]	@ fetch next sample

 

 	STRH	z1, [pBuffer], #NEXT_OUTPUT_PCM	@ write back to buffer

 

@@ -129,6 +128,5 @@
 	LDMFD	sp!,{r4-r10, lr}

 	BX		lr

 

-	.endfunc

 	.end

 

diff --git a/arm-wt-22k/lib_src/ARM-E_interpolate_loop_gnu.s b/arm-wt-22k/lib_src/ARM-E_interpolate_loop_gnu.s
index 2529e93..59ab0fd 100644
--- a/arm-wt-22k/lib_src/ARM-E_interpolate_loop_gnu.s
+++ b/arm-wt-22k/lib_src/ARM-E_interpolate_loop_gnu.s
@@ -56,7 +56,6 @@
 @SaveRegs	RLIST	{r4-r11,lr}

 @RestoreRegs	RLIST	{r4-r11,pc}

 

-	.func	WT_Interpolate

 WT_Interpolate:

 

 	STMFD	sp!,{r4-r11,lr}

@@ -81,13 +80,15 @@
 	SUBS	tmp0, pPhaseAccum, pLoopEnd		@ check for loop end

 	ADDGE	pPhaseAccum, pLoopStart, tmp0	@ loop back to start

 

-	.ifdef	SAMPLES_8_BIT

+	#ifdef	SAMPLES_8_BIT

 	LDRSB	tmp0, [pPhaseAccum]				@ tmp0 = x0

 	LDRSB	tmp1, [pPhaseAccum, #1]			@ tmp1 = x1

-	.else

+	#elif	SAMPLES_16_BIT

 	LDRSH	tmp0, [pPhaseAccum]				@ tmp0 = x0

 	LDRSH	tmp1, [pPhaseAccum, #2]			@ tmp1 = x1

-	.endif

+	#else

+	#error Must define one of SAMPLES_8_BIT or SAMPLES_16_BIT.

+	#endif

 

 	ADD		tmp2, phaseIncrement, phaseFrac	@ increment pointer here to avoid pipeline stall

 

@@ -101,11 +102,13 @@
 @ saturation operation should take in the filter before scaling back to

 @ 16 bits or the signal path should be increased to 18 bits or more.

 

-	.ifdef	SAMPLES_8_BIT

+	#ifdef	SAMPLES_8_BIT

 	MOV		tmp0, tmp0, LSL #6							@ boost 8-bit signal by 36dB

-	.else

+	#elif	SAMPLES_16_BIT

 	MOV		tmp0, tmp0, ASR #2							@ reduce 16-bit signal by 12dB

-	.endif															

+	#else

+	#error Must define one of SAMPLES_8_BIT or SAMPLES_16_BIT.

+	#endif

 	

 	ADD		tmp1, tmp0, tmp1, ASR #(NUM_EG1_FRAC_BITS-6)	@ tmp1 = tmp0 + (tmp1 >> (15-6))

 															@	   = x0 + f * (x1 - x0) == interpolated result

@@ -126,6 +129,5 @@
 	LDMFD	sp!,{r4-r11,lr}

 	BX		lr

 

-	.endfunc

 	.end

 	

diff --git a/arm-wt-22k/lib_src/ARM-E_interpolate_noloop_gnu.s b/arm-wt-22k/lib_src/ARM-E_interpolate_noloop_gnu.s
index 55a0ba7..baa6f7a 100644
--- a/arm-wt-22k/lib_src/ARM-E_interpolate_noloop_gnu.s
+++ b/arm-wt-22k/lib_src/ARM-E_interpolate_noloop_gnu.s
@@ -54,7 +54,6 @@
 @SaveRegs	RLIST	{r4-r9,lr}

 @RestoreRegs	RLIST	{r4-r9,pc}

 

-	.func	WT_InterpolateNoLoop

 WT_InterpolateNoLoop:

 

 	STMFD	sp!, {r4-r9,lr}

@@ -73,13 +72,15 @@
 

 InterpolationLoop:

 

-	.ifdef	SAMPLES_8_BIT

+	#ifdef	SAMPLES_8_BIT

 	LDRSB	tmp0, [pPhaseAccum]				@ tmp0 = x0

 	LDRSB	tmp1, [pPhaseAccum, #1]			@ tmp1 = x1

-	.else

+	#elif	SAMPLES_16_BIT

 	LDRSH	tmp0, [pPhaseAccum]				@ tmp0 = x0

 	LDRSH	tmp1, [pPhaseAccum, #2]			@ tmp1 = x1

-	.endif

+	#else

+	#error Must define one of SAMPLES_8_BIT or SAMPLES_16_BIT.

+	#endif

 

 	ADD		tmp2, phaseIncrement, phaseFrac	@ increment pointer here to avoid pipeline stall

 

@@ -93,11 +94,13 @@
 @ saturation operation should take in the filter before scaling back to

 @ 16 bits or the signal path should be increased to 18 bits or more.

 

-	.ifdef	SAMPLES_8_BIT

+	#ifdef	SAMPLES_8_BIT

 	MOV		tmp0, tmp0, LSL #6							@ boost 8-bit signal by 36dB

-	.else

+	#elif	SAMPLES_16_BIT

 	MOV		tmp0, tmp0, ASR #2							@ reduce 16-bit signal by 12dB

-	.endif															

+	#else

+	#error Must define one of SAMPLES_8_BIT or SAMPLES_16_BIT.

+	#endif

 	

 	ADD		tmp1, tmp0, tmp1, ASR #(NUM_EG1_FRAC_BITS-6)	@ tmp1 = tmp0 + (tmp1 >> (15-6))

 															@	   = x0 + f * (x1 - x0) == interpolated result

@@ -125,6 +128,5 @@
 	LDMFD	sp!,{r4-r9,lr}

 	BX		lr

 

-	.endfunc

 	.end

 	

diff --git a/arm-wt-22k/lib_src/ARM-E_mastergain_gnu.s b/arm-wt-22k/lib_src/ARM-E_mastergain_gnu.s
index f443fbb..e53bb99 100644
--- a/arm-wt-22k/lib_src/ARM-E_mastergain_gnu.s
+++ b/arm-wt-22k/lib_src/ARM-E_mastergain_gnu.s
@@ -40,7 +40,6 @@
 	.arm

 	.text

 

-	.func	SynthMasterGain

 SynthMasterGain:

 

 	.global	SynthMasterGain	@ allow other files to use this function

@@ -103,7 +102,5 @@
 

 @*****************************************************************************

 

-	.endfunc		@ end of function/procedure

-

 	.end		@ end of assembly code

 

diff --git a/arm-wt-22k/lib_src/ARM-E_voice_gain_gnu.s b/arm-wt-22k/lib_src/ARM-E_voice_gain_gnu.s
index 6ca28b2..9e1fcce 100644
--- a/arm-wt-22k/lib_src/ARM-E_voice_gain_gnu.s
+++ b/arm-wt-22k/lib_src/ARM-E_voice_gain_gnu.s
@@ -49,22 +49,21 @@
 

 numSamples	.req	r9

 

-	.if	STEREO_OUTPUT

+	#if	STEREO_OUTPUT

 gainIncLeft	.req	r7

 gainIncRight	.req	r8

 gainLeft	.req	r10

 gainRight	.req	r11

-	.else

+	#else

 gainIncrement	.req	r7

 gain	.req	r8

-	.endif

+	#endif

 

 

 @ register context for local variables

 @SaveRegs	RLIST	{r4-r11,lr}

 @RestoreRegs	RLIST	{r4-r11,pc}

 

-	.func	WT_VoiceGain

 WT_VoiceGain:

 

 	STMFD	sp!, {r4-r11,lr}

@@ -80,7 +79,7 @@
 @ due to storage and computational dependencies.

 @----------------------------------------------------------------

 

-	.if	STEREO_OUTPUT

+	#if	STEREO_OUTPUT

 

 	LDR		tmp0, [pWTFrame, #m_prevGain]

 	LDR		tmp1, [pWTFrame, #m_gainTarget]

@@ -132,7 +131,7 @@
 @----------------------------------------------------------------

 @ Mono version

 @----------------------------------------------------------------

-	.else

+	#else

 

 	LDR		gain, [pWTFrame, #m_prevGain]

 	MOV		gain, gain, LSL #(NUM_MIXER_GUARD_BITS + 4)

@@ -156,11 +155,10 @@
 	SUBS	numSamples, numSamples, #1

 	BGT		MonoGainLoop

 

-	.endif	@end Mono version

+	#endif	@end Mono version

 

 	LDMFD	sp!,{r4-r11,lr}

 	BX		lr

 	

-	.endfunc

 	.end

 

diff --git a/arm-wt-22k/lib_src/ARM_synth_constants_gnu.inc b/arm-wt-22k/lib_src/ARM_synth_constants_gnu.inc
index c0f8df3..213944e 100644
--- a/arm-wt-22k/lib_src/ARM_synth_constants_gnu.inc
+++ b/arm-wt-22k/lib_src/ARM_synth_constants_gnu.inc
@@ -12,45 +12,45 @@
 @****************************************************************
 
 
-    .ifdef  SAMPLE_RATE_8000
+    #ifdef  SAMPLE_RATE_8000
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 5
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 32
-    .endif
+    #endif
 
-    .ifdef  SAMPLE_RATE_16000
+    #ifdef  SAMPLE_RATE_16000
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 6
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 64
-    .endif
+    #endif
 
-    .ifdef  SAMPLE_RATE_20000
+    #ifdef  SAMPLE_RATE_20000
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 7
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 128
-    .endif
+    #endif
 
-    .ifdef  SAMPLE_RATE_22050
+    #ifdef  SAMPLE_RATE_22050
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 7
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 128
-    .endif
+    #endif
 
-    .ifdef  SAMPLE_RATE_24000
+    #ifdef  SAMPLE_RATE_24000
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 7
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 128
-    .endif
+    #endif
 
-    .ifdef  SAMPLE_RATE_32000
+    #ifdef  SAMPLE_RATE_32000
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 7
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 128
-    .endif
+    #endif
 
-    .ifdef  SAMPLE_RATE_44100
+    #ifdef  SAMPLE_RATE_44100
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 8
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 256
-    .endif
+    #endif
 
-    .ifdef  SAMPLE_RATE_48000
+    #ifdef  SAMPLE_RATE_48000
     .equ    SYNTH_UPDATE_PERIOD_IN_BITS, 8
     .equ    BUFFER_SIZE_IN_MONO_SAMPLES, 256
-    .endif
+    #endif
 
 
 @ if the OUTPUT PCM sample is 16-bits, then when using indexed addressing,
@@ -64,13 +64,13 @@
     .equ    PHASE_FRAC_MASK, 0x7FFF
 
 @ shift for phase accumulator when fraction carries over
-    .ifdef  SAMPLES_8_BIT
+    #ifdef  SAMPLES_8_BIT
     .equ    NEXT_INPUT_PCM_SHIFT, 0
-    .endif
+    #endif
 
-    .ifdef  SAMPLES_16_BIT
+    #ifdef  SAMPLES_16_BIT
     .equ    NEXT_INPUT_PCM_SHIFT, 1
-    .endif
+    #endif
 
 @****************************************************************************
     .equ    NUM_MIXER_GUARD_BITS, 4
@@ -90,19 +90,19 @@
 @ handle a struct in a compatible fashion. Switching to old fashion EQU
 @
 
-    .if FILTER_ENABLED
+    #if FILTER_ENABLED
 @**************************************
 @ typedef struct s_filter_tag
     .equ    m_z1, 0
     .equ    m_z2, 2
-    .endif
+    #endif
 
 @**************************************
 @ typedef struct s_wt_frame_tag
     .equ    m_gainTarget, 0
     .equ    m_phaseIncrement, 4
 
-    .if FILTER_ENABLED
+    #if FILTER_ENABLED
     .equ    m_k, 8
     .equ    m_b1, 12
     .equ    m_b2, 16
@@ -110,12 +110,12 @@
     .equ    m_pMixBuffer, 24
     .equ    m_numSamples, 28
     .equ    m_prevGain, 32
-    .else
+    #else
     .equ    m_pAudioBuffer, 8
     .equ    m_pMixBuffer, 12
     .equ    m_numSamples, 16
     .equ    m_prevGain, 20
-    .endif
+    #endif
 
 
 @**************************************
@@ -125,10 +125,10 @@
     .equ    m_pPhaseAccum, 8    @ /* points to first sample at start of loop */
     .equ    m_phaseFrac, 12 @ /* points to first sample at start of loop */
 
-    .if STEREO_OUTPUT
+    #if STEREO_OUTPUT
     .equ    m_gainLeft, 16  @ /* current gain, left ch  */
     .equ    m_gainRight, 18 @ /* current gain, right ch */
-    .endif
+    #endif
 
 
 @****************************************************************************