OSDN Git Service

[VM][I386] Remove compiler warning conversion float64 (a.k.a UINT64) <-> double....
authorK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 14 Jun 2018 12:56:53 +0000 (21:56 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Thu, 14 Jun 2018 12:56:53 +0000 (21:56 +0900)
source/src/vm/libcpu_newdev/libcpu_i386/i386_opdef.cpp
source/src/vm/libcpu_newdev/libcpu_i386/i386_opdef.h

index 1c4c49a..0c44e81 100644 (file)
@@ -54,7 +54,7 @@ UINT32 I386_OPS_BASE::i386_load_protected_mode_segment( I386_SREG *seg, UINT64 *
        }
 
        entry = seg->selector & ~0x7;
-       if (limit == 0 || entry + 7 > limit)
+       if ((limit == 0) || ((UINT32)(entry + 7) > limit))
                return 0;
 
        v1 = READ32PL0(base + entry );
@@ -89,7 +89,7 @@ void I386_OPS_BASE::i386_load_call_gate(I386_CALL_GATE *gate)
        }
 
        entry = gate->segment & ~0x7;
-       if (limit == 0 || entry + 7 > limit)
+       if ((limit == 0) || ((UINT32)(entry + 7) > limit))
                return;
 
        v1 = READ32PL0(base + entry );
@@ -923,7 +923,7 @@ void I386_OPS_BASE::i386_trap(int irq, int irq_gate, int trap_level)
                                        else
                                                stack_limit = 6;
                                        // TODO: Add check for error code (2 extra bytes)
-                                       if(REG32(ESP) < stack_limit)
+                                       if((int)(REG32(ESP)) < stack_limit)
                                        {
                                                logerror("IRQ: Stack has no space left (needs %i bytes).\n",stack_limit);
                                                FAULT_EXP(FAULT_SS,0)
@@ -1787,7 +1787,7 @@ void I386_OPS_BASE::i386_protected_mode_call( UINT16 seg, UINT32 off, int indire
                                        }
                                        if(operand32 != 0)
                                        {
-                                               if(newESP < ((gate.dword_count & 0x1f) + 16))
+                                               if(newESP < (UINT32)((gate.dword_count & 0x1f) + 16))
                                                {
                                                        logerror("CALL: Call gate: New stack has no room for 32-bit return address and parameters.\n");
                                                        FAULT(FAULT_SS,0) // #SS(0)
@@ -1800,7 +1800,7 @@ void I386_OPS_BASE::i386_protected_mode_call( UINT16 seg, UINT32 off, int indire
                                        }
                                        else
                                        {
-                                               if(newESP < ((gate.dword_count & 0x1f) + 8))
+                                               if(newESP < (UINT32)((gate.dword_count & 0x1f) + 8))
                                                {
                                                        logerror("CALL: Call gate: New stack has no room for 16-bit return address and parameters.\n");
                                                        FAULT(FAULT_SS,0) // #SS(0)
@@ -2696,7 +2696,7 @@ void I386_OPS_BASE::i386_protected_mode_iret(int operand32)
 
 void I386_OPS_BASE::build_cycle_table()
 {
-       int i, j;
+       uint32_t i, j;
        for (j=0; j < X86_NUM_CPUS; j++)
        {
 //             cycle_table_rm[j] = (UINT8 *)malloc(CYCLES_NUM_OPCODES);
@@ -2986,7 +2986,7 @@ void I386_OPS_BASE::build_opcode_table(UINT32 features)
                _cpustate->lock_table[1][i] = false;
        }
 
-       for (i=0; i < sizeof(x86_opcode_table)/sizeof(X86_OPCODE); i++)
+       for (i=0; i < (int)(sizeof(x86_opcode_table) / sizeof(X86_OPCODE)); i++)
        {
                const X86_OPCODE *op = &x86_opcode_table[i];
 
index 717d2f9..e47ace6 100644 (file)
@@ -1816,6 +1816,8 @@ protected:
        INLINE int floatx80_is_inf(floatx80 fx);
        INLINE int floatx80_is_denormal(floatx80 fx);
        INLINE floatx80 floatx80_abs(floatx80 fx);
+
+       INLINE UINT64 __SWAP64(UINT64 in);
        INLINE double fx80_to_double(floatx80 fx);
        INLINE floatx80 double_to_fx80(double in);
        INLINE floatx80 READ80( UINT32 ea);
@@ -2809,15 +2811,57 @@ INLINE floatx80 I386_OPS_BASE::floatx80_abs(floatx80 fx)
        return fx;
 }
 
+inline UINT64 I386_OPS_BASE::__SWAP64(UINT64 in)
+{                                              
+       typedef union {                                                                         
+               struct {                                                                        
+                       uint8_t h7, h6, h5, h4, h3, h2, h, l;   
+               } b;   
+               UINT64 ld;
+       } d1_t;
+       
+       d1_t id, od;
+       id.ld = in;
+       od.b.h7 = id.b.l;
+       od.b.h6 = id.b.h;
+       od.b.h5 = id.b.h2;
+       od.b.h4 = id.b.h3;
+       od.b.h3 = id.b.h4;
+       od.b.h2 = id.b.h5;
+       od.b.h  = id.b.h6;
+       od.b.l  = id.b.h7;
+       
+       return od.ld;
+}
+
 INLINE double I386_OPS_BASE::fx80_to_double(floatx80 fx)
 {
-       UINT64 d = floatx80_to_float64(fx);
-       return *(double*)&d;
+       union {
+               UINT64 ld;
+               double fd; // WIP: If sizeof(double) != sizeof(UINT64).(or IEEE 754 format has changed).
+       } d;
+       UINT64 nd;
+       nd = floatx80_to_float64(fx);
+#if __FLOAT_WORD_ORDER != __BYTE_ORDER
+       nd = __SWAP64(nd);
+#endif
+       d.ld = nd;
+       return d.fd;
 }
 
 INLINE floatx80 I386_OPS_BASE::double_to_fx80(double in)
 {
-       return float64_to_floatx80(*(UINT64*)&in);
+       union {
+               UINT64 ld;
+               double fd; // WIP: If sizeof(double) != sizeof(UINT64).(or IEEE 754 format has changed).
+       } d;
+       UINT64 nd;
+       d.fd = in;
+       nd = d.ld;
+#if __FLOAT_WORD_ORDER != __BYTE_ORDER
+       nd = __SWAP64(nd);
+#endif
+       return float64_to_floatx80(nd);
 }
 
 INLINE floatx80 I386_OPS_BASE::READ80( UINT32 ea)