Dear NXP Team,
Compiling a C source file using your GCC for PPC VLE we encountered a problem. The compiler successfully completed but the assembler rejected the generated assembly file in the second pass. Inspection of the assembly listing revealed an invalid instruction, which had been emitted by the compiler pass.
The C compiler is:
"powerpc-eabivle-gcc.exe (GCC) 4.9.4 20160726 (Sat May 27 11:09:55 CDT 2017 build.sh rev=gd8b6c20 s=F494 ELe200 -V release_gd8b6c20_build_Fed_ELe200_ML0)"
This is the command line. We have removed some -I<path> switches. The problem appeared with -O3 and likely with -Os but not with -O2:
powerpc-eabivle-gcc.exe -c -mcpu=e200z4 -mbig-endian -mvle -misel=yes -meabi -msdata=default -G8 -mregnames -fshort-double -fsingle-precision-constant -mhard-float -mno-string -fno-common -fno-exceptions -ffunction-sections -fdata-sections -fshort-enums -fdiagnostics-show-option -finline-functions -fmessage-length=0 -fzero-initialized-in-bss -fno-tree-loop-optimize -Wall -Wno-main -Wno-old-style-declaration -Wextra -Wstrict-overflow=4 -Wmissing-declarations -Wno-parentheses -Wdiv-by-zero -Wcast-align -Wformat -Wformat-security -Wignored-qualifiers -Wsign-conversion -Wsign-compare -Werror=missing-declarations -Werror=implicit-function-declaration -Wno-nested-externs -Werror=int-to-pointer-cast -Werror=pointer-sign -Werror=pointer-to-int-cast -Werror=return-local-addr -Werror=missing-prototypes -Werror=missing-field-initializers --sysroot=C:/ProgramFiles/MinGW-powerpc-eabivle-4.9.4/powerpc-eabivle/newlib -MMD -std=gnu11 -Icode -DPRODUCTION -DNDEBUG -DTL42 -g1 -gdwarf-2 -O3 -o bin/ppc/PRODUCTION/obj/bcc_ulim5.o thisFolderStandsForAnyPathToCustomerCode/codeSampleCustomer/Integration/sohr5.c
Our problem analysis:
For source code line 265, the compiler emits the instruction
e_bc 1,28,$+12
The instruction tries to evaluate the compare register CR7, which is not permitted in this VLE instruction. The original Book E instruction bc uses the 5 Bit field BI to select a compare result bit and would allow the value of 28 (see EREF, 6.4, p. 413) but the VLE instruction e_bc has only 4 Bit for field BI32 (despite of its name) and restricts the range of accessible compare result bits to 0..15 (see VLE, p. 3-13 = 45). Accordingly, the assembler complains about the 28.
Many other assembly code locations from the same file make use of instruction e_mcrf to first move the otherwise inaccessible compare result bits to the accessible range and evaluate only then (see snippet below). The faulty code pattern has seen just once in the entire project.
EREF: "EREF: A Programmer's Reference Manual for Freescale Power Architecture Processors", EREF_RM, Rev. 1 (EIS 2.1), 06/2014
VLE: "Variable-Length Encoding (VLE) Programming Environments Manual: A Supplement to the EREF", VLEPEM, Rev. 0, 07/2007
Here is a snippet from the generated assembly code (written by the compiler). Unfortunately, the full assembly listing and the original source file can't be disclosed because of intellectual property concerns:
(..)
.L247:
.loc 1 4672 0
e_mcrf %cr0,%cr7
e_beq %cr0,.L248
.loc 1 4673 0
e_lbz %r6,Sbccsohr5124_RSWE@sda21(%r0)
se_cmpi %r6,0
e_beq %cr0,.L249
e_lhz %r24,X_Sbccsohr5124_Unit_Delay6@sda21(%r0)
.L250:
(..)
.L262:
.loc 1 4798 0
e_beq %cr1,.L263
.loc 1 4799 0
e_lbz %r6,Sbccsohr5121_RSWE@sda21(%r0)
e_cmpi %cr1,%r6,0
e_beq %cr1,.L264
e_lhz %r0,X_Sbccsohr5121_Unit_Delay6@sda21(%r0)
.L265:
cmpl %cr7,%r7,%r0
e_bc 1,28,$+12 /* Book E instruction bc used as (invalid) VLE instruction e_bc */
mr %r6,%r7
e_b $+8
mr %r6,%r0
e_sth %r6,Sbccsohr5121_Modl2@sda21(%r0)
.loc 1 4823 0
e_sth %r6,X_Sbccsohr5121_Unit_Delay6@sda21(%r0)
(..)
Kind regards
Peter Vranken