Part Number: TMS320F28377D
Tool/software: TI C/C++ Compiler
I found this issue whilst investigating other issue
% cat i16tof32_v_attempt2.c
static inline float stof1(const short *x) { return (float)*x; }
void i16tof32_v_attempt2(float *y, const short *x, short num)
{
while (num--) *y++ = stof1(x++);
}
% "C:/ti/ccsv6/tools/compiler/ti-cgt-c2000_16.9.2.LTS/bin/cl2000" -v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --vcu_support=vcu2 -O3 --opt_for_speed=5 --fp_mode=relaxed --include_path="C:/ti/ccsv6/tools/compiler/ti-cgt-c2000_16.9.2.LTS/include" --symdebug:none --diag_warning=225 --diag_wrap=off --display_error_number -k --src_interlist "i16tof32_v_attemp2.c"
% cat i16tof32_v_attempt2.asm
;***************************************************************
;* TMS320C2000 C/C++ Codegen PC v16.9.2.LTS *
;* Date/Time created: Tue Apr 04 12:00:44 2017 *
;***************************************************************
.compiler_opts --abi=coffabi --cla_support=cla1 --diag_wrap=off --float_support=fpu32 --hll_source=on --mem_model:code=flat --mem_model:data=large --object_format=coff --silicon_version=28 --symdebug:none --tmu_support=tmu0
.asg XAR2, FP
; C:\ti\ccsv6\tools\compiler\ti-cgt-c2000_16.9.2.LTS\bin\opt2000.exe C:\\Users\\rist-1\\AppData\\Local\\Temp\\023402 C:\\Users\\rist-1\\AppData\\Local\\Temp\\023404
; C:\ti\ccsv6\tools\compiler\ti-cgt-c2000_16.9.2.LTS\bin\ac2000.exe -@C:\\Users\\rist-1\\AppData\\Local\\Temp\\0234012
.sect ".text"
.clink
.global _i16tof32_v_attempt2
;***************************************************************
;* FNAME: _i16tof32_v_attempt2 FR SIZE: 0 *
;* *
;* FUNCTION ENVIRONMENT *
;* *
;* FUNCTION PROPERTIES *
;* 0 Parameter, 0 Auto, 0 SOE *
;***************************************************************
_i16tof32_v_attempt2:
;*** 5 ----------------------- if ( !num ) goto g7;
CMPB AL,#0 ; [CPU_] |5|
B $C$L3,EQ ; [CPU_] |5|
; branchcc occurs ; [] |5|
;*** 5 ----------------------- d$1 = num&1;
;*** 5 ----------------------- if ( num < 2 ) goto g5;
AND AH,AL,#0x0001 ; [CPU_] |5|
CMPB AL,#2 ; [CPU_] |5|
B $C$L2,LT ; [CPU_] |5|
; branchcc occurs ; [] |5|
;*** ----------------------- L$1 = (num>>1)-1;
;*** ----------------------- #pragma MUST_ITERATE(1, 16383, 1)
;*** ----------------------- // LOOP BELOW UNROLLED BY FACTOR(2)
;*** ----------------------- #pragma LOOP_FLAGS(4102u)
;*** -----------------------g4:
;*** 1 ----------------------- *y++ = (float)*x++; // [0]
;*** 1 ----------------------- x = x; // [0]
;*** 1 ----------------------- ++x; // [0]
;*** 1 ----------------------- *y++ = (float)*x; // [0]
;*** 5 ----------------------- if ( (--L$1) != (-1) ) goto g4;
ASR AL,1 ; [CPU_]
ADDB AL,#-1 ; [CPU_]
MOVZ AR6,AL ; [CPU_]
RPTB $C$L2,AR6 ; [CPU_] |5|
; repeat block starts ; []
$C$L1:
MOVX TL,*XAR5++ ; [CPU_] |1|
MOV32 R0H,XT ; [CPU_] |1|
NOP ; [CPU_]
NOP ; [CPU_]
NOP ; [CPU_]
NOP ; [CPU_]
I32TOF32 R1H,R0H ; [CPU_] |1|
NOP ; [CPU_]
MOV32 *XAR4++,R1H ; [CPU_] |1|
MOV32 *XAR4++,R0H ; [CPU_] |1|
; repeat block ends ; []
$C$L2:
;*** -----------------------g5:
;*** ----------------------- if ( d$1 <= 0 ) goto g7;
CMPB AH,#0 ; [CPU_]
B $C$L3,LEQ ; [CPU_]
; branchcc occurs ; []
; Peeled loop iterations for unrolled loop:
;*** 1 ----------------------- *y = (float)*x; // [0]
;*** -----------------------g7:
;*** ----------------------- return;
I16TOF32 R0H,*+XAR5[0] ; [CPU_] |1|
NOP ; [CPU_]
MOV32 *+XAR4[0],R0H ; [CPU_] |1|
$C$L3:
LRETR ; [CPU_]
; return occurs ; []
;* Inlined function references:
;* [0] stof1
The C code is converting an array of 16-bit integers to an array of 32-bit floats. Look at the unrolled loop in the assembly; the loop is only performing a single conversion, and is pushing the 32-bit float to the output, then pushing the sign-extended 16-bit input to the output. It is also missing the second half of the input array.
Am I provoking an undefined behaviour that I am unaware of, or is this a compiler issue?