Bob Haarman | ac82f6c | 2020-09-08 18:59:40 +0000 | [diff] [blame] | 1 | commit 8ddb05ad09a873375be6179d33a9bcd330112c43 |
| 2 | Author: John Hodge <tpg@mutabah.net> |
| 3 | Date: Sun Nov 10 20:39:40 2019 +0800 |
| 4 | |
| 5 | Codegen C - Fix errors from travis OSX |
| 6 | |
| 7 | diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp |
| 8 | index 85246749..20ff95cb 100644 |
| 9 | --- a/src/trans/codegen_c.cpp |
| 10 | +++ b/src/trans/codegen_c.cpp |
| 11 | @@ -602,7 +602,12 @@ namespace { |
| 12 | } |
| 13 | else |
| 14 | { |
| 15 | - m_of << "static inline uint128_t __mrustc_bitrev128(uint128_t v) { if(v==0) return 0; uint128_t rv = ((uint128_t)__mrustc_bitrev64(v>>64))|((uint128_t)__mrustc_bitrev64(v)<<64); }\n"; |
| 16 | + m_of << "static inline uint128_t __mrustc_bitrev128(uint128_t v) {" |
| 17 | + << " if(v==0) return 0;" |
| 18 | + << " uint128_t rv = ((uint128_t)__mrustc_bitrev64(v>>64))|((uint128_t)__mrustc_bitrev64(v)<<64);" |
| 19 | + << " return rv;" |
| 20 | + << " }\n" |
| 21 | + ; |
| 22 | } |
| 23 | for(int sz = 8; sz <= 64; sz *= 2) |
| 24 | { |
| 25 | @@ -3949,9 +3954,15 @@ namespace { |
| 26 | if (::std::strcmp(r, "{eax}") == 0 || ::std::strcmp(r, "{rax}") == 0) { |
| 27 | return "a"; |
| 28 | } |
| 29 | + else if (::std::strcmp(r, "{ebx}") == 0 || ::std::strcmp(r, "{rbx}") == 0) { |
| 30 | + return "b"; |
| 31 | + } |
| 32 | else if (::std::strcmp(r, "{ecx}") == 0 || ::std::strcmp(r, "{rcx}") == 0) { |
| 33 | return "c"; |
| 34 | } |
| 35 | + else if (::std::strcmp(r, "{edx}") == 0 || ::std::strcmp(r, "{rdx}") == 0) { |
| 36 | + return "d"; |
| 37 | + } |
| 38 | else { |
| 39 | return r; |
| 40 | } |
| 41 | @@ -4010,12 +4021,16 @@ namespace { |
| 42 | { |
| 43 | const auto& v = e.inputs[i]; |
| 44 | if (i != 0) m_of << ", "; |
| 45 | + // TODO: If this is the same reg as an output, use the output index |
| 46 | m_of << "\"" << H::convert_reg(v.first.c_str()) << "\" ("; emit_lvalue(v.second); m_of << ")"; |
| 47 | } |
| 48 | m_of << ": "; |
| 49 | for (unsigned int i = 0; i < e.clobbers.size(); i++) |
| 50 | { |
| 51 | if (i != 0) m_of << ", "; |
| 52 | + if( e.tpl == "cpuid\n" && e.clobbers[i] == "rbx" ) { |
| 53 | + continue; |
| 54 | + } |
| 55 | m_of << "\"" << e.clobbers[i] << "\""; |
| 56 | } |
| 57 | m_of << ");\n"; |
| 58 | @@ -5214,6 +5229,7 @@ namespace { |
| 59 | auto ordering = get_atomic_ordering(name, 7+4+1); |
| 60 | const auto& ty = params.m_types.at(0); |
| 61 | emit_lvalue(e.ret_val); m_of << " = __mrustc_atomicloop" << get_prim_size(ty) << "("; |
| 62 | + m_of << "(volatile "; emit_ctype(ty); m_of << "*)"; |
| 63 | emit_param(e.args.at(0)); m_of << ", "; emit_param(e.args.at(1)); |
| 64 | if( m_compiler == Compiler::Gcc ) |
| 65 | { |
| 66 | @@ -5236,6 +5252,7 @@ namespace { |
| 67 | const auto& ty = params.m_types.at(0); |
| 68 | const char* op = (name.c_str()[7+1] == 'a' ? "imax" : "imin"); // m'a'x vs m'i'n |
| 69 | emit_lvalue(e.ret_val); m_of << " = __mrustc_atomicloop" << get_prim_size(ty) << "("; |
| 70 | + m_of << "(volatile "; emit_ctype(ty); m_of << "*)"; |
| 71 | emit_param(e.args.at(0)); m_of << ", "; emit_param(e.args.at(1)); |
| 72 | if( m_compiler == Compiler::Gcc ) |
| 73 | { |
| 74 | @@ -5250,6 +5267,7 @@ namespace { |
| 75 | const auto& ty = params.m_types.at(0); |
| 76 | const char* op = (name.c_str()[7+2] == 'a' ? "umax" : "umin"); // m'a'x vs m'i'n |
| 77 | emit_lvalue(e.ret_val); m_of << " = __mrustc_atomicloop" << get_prim_size(ty) << "("; |
| 78 | + m_of << "(volatile "; emit_ctype(ty); m_of << "*)"; |
| 79 | emit_param(e.args.at(0)); m_of << ", "; emit_param(e.args.at(1)); |
| 80 | if( m_compiler == Compiler::Gcc ) |
| 81 | { |