| 1083 | |
| 1084 | template<class sint, class sgf2n> |
| 1085 | void Processor<sint, sgf2n>::fixinput(const Instruction& instruction) |
| 1086 | { |
| 1087 | int n = instruction.get_n(); |
| 1088 | if (n == P.my_num() or n == -1) |
| 1089 | { |
| 1090 | typename sint::clear tmp; |
| 1091 | bool use_double = false; |
| 1092 | switch (instruction.get_r(2)) |
| 1093 | { |
| 1094 | case 0: |
| 1095 | case 1: |
| 1096 | break; |
| 1097 | case 2: |
| 1098 | use_double = true; |
| 1099 | break; |
| 1100 | default: |
| 1101 | throw runtime_error("unknown format for fixed-point input"); |
| 1102 | } |
| 1103 | |
| 1104 | if (not sint::real_shares(P)) |
| 1105 | return; |
| 1106 | |
| 1107 | if (binary_input.fail()) |
| 1108 | throw IO_Error( |
| 1109 | "Failure reading from " + binary_input_filename |
| 1110 | + ". You might need to copy it " |
| 1111 | + "from the location of compilation."); |
| 1112 | |
| 1113 | if (binary_input.peek() == EOF) |
| 1114 | throw IO_Error("not enough inputs in " + binary_input_filename); |
| 1115 | |
| 1116 | if (instruction.get_r(2) == 0) |
| 1117 | { |
| 1118 | if (instruction.get_r(1) == 1) |
| 1119 | fixinput_int(*this, instruction, int8_t()); |
| 1120 | else |
| 1121 | fixinput_int(*this, instruction, int64_t()); |
| 1122 | } |
| 1123 | else |
| 1124 | { |
| 1125 | for (int i = 0; i < instruction.get_size(); i++) |
| 1126 | { |
| 1127 | double buf; |
| 1128 | if (use_double) |
| 1129 | binary_input.read((char*) &buf, sizeof(double)); |
| 1130 | else |
| 1131 | { |
| 1132 | float x; |
| 1133 | binary_input.read((char*) &x, sizeof(float)); |
| 1134 | buf = x; |
| 1135 | } |
| 1136 | tmp = bigint::tmp = round(buf * exp2(instruction.get_r(1))); |
| 1137 | write_Cp(instruction.get_r(0) + i, tmp); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | if (binary_input.fail()) |
| 1142 | throw IO_Error("failure reading from " + binary_input_filename); |
no test coverage detected