Skip to content

Commit

Permalink
don't emit fcmpeq and fcmpne
Browse files Browse the repository at this point in the history
  • Loading branch information
keiichiw committed Mar 12, 2015
1 parent 02b9902 commit 4b8d9ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/emitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ let emit_global_var name init =
| _ -> raise_error "emit_global_var: invalid int constant (size = %d)" (sizeof ty)
end
| EConst (_, VFloat v) ->
let v = if v = 0.0 then 0.0 else v in
emit ".float %.15F" v
| EConst (_, VStr v) ->
emit ".string \"%s\"" (escaped v)
Expand Down Expand Up @@ -305,6 +306,7 @@ let rec ex ret_reg = function
| VInt i ->
emit "mov r%d, %d" ret_reg i
| VFloat f ->
let f = if f = 0.0 then 0.0 else f in
emit "mov r%d, %F" ret_reg f
| VStr _ ->
raise_error "logic flaw: EConst at Emitter.ex"
Expand Down Expand Up @@ -431,16 +433,12 @@ let rec ex ret_reg = function
| Ge -> "fcmpge"
| Gt -> "fcmpgt" in
emit_bin ret_reg op e1 e2
| EEq (_, op, e1, e2) ->
| EEq (_, op, e1, e2)
| EFEq (_, op, e1, e2) ->
let op = match op with
| Eq -> "cmpeq"
| Ne -> "cmpne" in
emit_bin ret_reg op e1 e2
| EFEq (_, op, e1, e2) ->
let op = match op with
| Eq -> "fcmpeq"
| Ne -> "fcmpne" in
emit_bin ret_reg op e1 e2
| EPAdd (ty, e1, e2) ->
begin match ty with
| TPtr ty ->
Expand Down
9 changes: 9 additions & 0 deletions test/float-cond.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
0
OK
OK
OK
OK
OK
*/

#include <stdio.h>
Expand All @@ -14,6 +17,7 @@ int main()
{
float t = 0.1;
float f = -0.0;
int ti = (0 == 0.0 * -1.0);
printf("%d\n", 0.0 ? 1 : 0);
printf("%d\n", -0.0 ? 1 : 0);
printf("%d\n", 0.1 ? 1 : 0);
Expand All @@ -24,4 +28,9 @@ int main()
if ( 0.1) printf("OK\n");
if (t) printf("OK\n");
if (f) printf("NG\n");
if (0.0 == -0.0) printf("OK\n");
if (0.0 != -0.0) printf("NG\n");
if (0.0 == 0.0 * -1.0) printf("OK\n");
if (0.0 != -0.0) printf("NG\n");
if (ti) printf("OK\n");
}

0 comments on commit 4b8d9ac

Please sign in to comment.