Details
-
Bug
-
Status: Accepted
-
Medium
-
Resolution: Unresolved
-
Code Generation Tools
-
CODEGEN-8400
-
-
default
Description
The attached main.cpp has these lines ...
int main() { const float a = 0.0f; const float b = -0.0f; const float c = std::copysign(0.0f, -1.0f); std::printf("%08x\n", byte_cast<uint32_t>(a)); // expected: 0x00000000, actual: 0x00000000 std::printf("%08x\n", byte_cast<uint32_t>(b)); // expected: 0x80000000, actual: 0x00000000 std::printf("%08x\n", byte_cast<uint32_t>(c)); // expected: 0x80000000, actual: 0x80000000 assert(std::signbit(a) == false); // ok assert(std::signbit(b) == true); // fails! assert(std::signbit(c) == true); // ok }
Build it ...
"C:/ti/compilers/ti-cgt-arm_18.12.3.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=none -me -O3 --opt_for_speed=4 --include_path="C:/Users/a0321429/workspace_v10_1/negative_zero_test_cc1352r1" --include_path="C:/ti/compilers/ti-cgt-arm_18.12.3.LTS/include" -g --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --ramfunc=off --src_interlist --preproc_with_compile --preproc_dependency="main.d_raw" "../main.cpp"
When the code is executed, this is the output ...
00000000 00000000 80000000 Assertion failed, (std::signbit(b) == true), file ../main.cpp, line 25
The second line should be 80000000. No assertion should fail.
Here is part of the assembly output in main.asm ...
;** 18 ----------------------- a = 0.0F; ;** 19 ----------------------- b = -0.0F; ;* 1080 ----------------------- c = copysignf(C$11 = 0.0F, -1.0F); // [1] ;** 12 ----------------------- memcpy(&result, &a, 4u); // [3] ;** 21 ----------------------- printf[VA](C$12 = "%08x\n", (unsigned)result); ;** 12 ----------------------- memcpy(&result, &b, 4u); // [3] ;** 22 ----------------------- printf[VA](C$12, (unsigned)result); ;** 12 ----------------------- memcpy(&result, &c, 4u); // [3] ;** 23 ----------------------- printf[VA](C$12, (unsigned)result); ;** 24 ----------------------- assert((_ftoi(C$11)&0x80000000u) == 0); PUSH {V1, V2, LR} ; [DPU_V7M3_PIPE] .dwcfi cfa_offset, 12 .dwcfi save_reg_to_mem, 14, -4 .dwcfi save_reg_to_mem, 5, -8 .dwcfi save_reg_to_mem, 4, -12 .dwpsn file "../main.cpp",line 18,column 19,is_stmt,isa 1 MOVS V1, #0 ; [DPU_V7M3_PIPE] |18| .dwpsn file "C:/ti/compilers/ti-cgt-arm_18.12.3.LTS/include/libcxx/math.h",line 1080,column 3,is_stmt,isa 1 MOVS A2, #0 ; [DPU_V7M3_PIPE] |1080| SUB SP, SP, #28 ; [DPU_V7M3_PIPE] .dwcfi cfa_offset, 40 .dwpsn file "../main.cpp",line 18,column 19,is_stmt,isa 1 MOVT V1, #0 ; [DPU_V7M3_PIPE] |18| .dwpsn file "C:/ti/compilers/ti-cgt-arm_18.12.3.LTS/include/libcxx/math.h",line 1080,column 3,is_stmt,isa 1 MOVT A2, #49024 ; [DPU_V7M3_PIPE] |1080| .dwpsn file "../main.cpp",line 18,column 19,is_stmt,isa 1 STR V1, [SP, #0] ; [DPU_V7M3_PIPE] |18| .dwpsn file "C:/ti/compilers/ti-cgt-arm_18.12.3.LTS/include/libcxx/math.h",line 1080,column 3,is_stmt,isa 1 MOV A1, V1 ; [DPU_V7M3_PIPE] |1080| .dwpsn file "../main.cpp",line 19,column 19,is_stmt,isa 1 STR V1, [SP, #4] ; [DPU_V7M3_PIPE] |19|
The last STR should store the value 0x80000000 to that memory location on the stack. But it stores 0 instead.
Also attached is a CCS project which runs on a LAUNCHXL-CC1352R1.