authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-12-04 23:50:11-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:15:04-07:00
logce4e5fee6346d142a7a98d5c56a056ff8a25e1f1
tree94b8d22278a63ce484a09394adf0378e7f32516c
parent54b960aa4dc335a9f9c6985ac869dd88fdf2321a

wasm2c: avoid aliasing issues on memory access


1 files changed, 170 insertions(+), 212 deletions(-)

stage1/wasm2c.c+170-212
......@@ -78,7 +78,7 @@ int main(int argc, char **argv) {
7878 }
7979
8080 const char *mod = "wasm";
81 bool isBigEndian = false; // TODO
81 bool is_big_endian = false; // TODO
8282
8383 struct InputStream in;
8484 InputStream_open(&in, argv[1]);
......@@ -95,6 +95,112 @@ int main(int argc, char **argv) {
9595 "#include <stdint.h>\n"
9696 "#include <stdlib.h>\n"
9797 "#include <string.h>\n"
98 "\n", out);
99 if (is_big_endian)
100 fputs("static uint16_t i16_byteswap(uint16_t src) {\n"
101 " return (uint16_t)(uint8_t)(src >> 0) << 8 |\n"
102 " (uint16_t)(uint8_t)(src >> 8) << 0;\n"
103 "}\n"
104 "static uint32_t i32_byteswap(uint32_t src) {\n"
105 " return (uint32_t)i16_byteswap(src >> 0) << 16 |\n"
106 " (uint32_t)i16_byteswap(src >> 16) << 0;\n"
107 "}\n"
108 "static uint64_t i64_byteswap(uint64_t src) {\n"
109 " return (uint64_t)i32_byteswap(src >> 0) << 32 |\n"
110 " (uint64_t)i32_byteswap(src >> 32) << 0;\n"
111 "}\n"
112 "\n", out);
113 fputs("static uint16_t load16_align0(const uint8_t *ptr) {\n"
114 " uint16_t val;\n"
115 " memcpy(&val, ptr, sizeof(val));\n", out);
116 if (is_big_endian) fputs(" val = i16_byteswap(val);", out);
117 fputs(" return val;\n"
118 "}\n"
119 "static uint16_t load16_align1(const uint16_t *ptr) {\n"
120 " uint16_t val;\n"
121 " memcpy(&val, ptr, sizeof(val));\n", out);
122 if (is_big_endian) fputs(" val = i16_byteswap(val);", out);
123 fputs(" return val;\n"
124 "}\n"
125 "static uint32_t load32_align0(const uint8_t *ptr) {\n"
126 " uint32_t val;\n"
127 " memcpy(&val, ptr, sizeof(val));\n", out);
128 if (is_big_endian) fputs(" val = i32_byteswap(val);", out);
129 fputs(" return val;\n"
130 "}\n"
131 "static uint32_t load32_align1(const uint16_t *ptr) {\n"
132 " uint32_t val;\n"
133 " memcpy(&val, ptr, sizeof(val));\n", out);
134 if (is_big_endian) fputs(" val = i32_byteswap(val);", out);
135 fputs(" return val;\n"
136 "}\n"
137 "static uint32_t load32_align2(const uint32_t *ptr) {\n"
138 " uint32_t val;\n"
139 " memcpy(&val, ptr, sizeof(val));\n", out);
140 if (is_big_endian) fputs(" val = i32_byteswap(val);", out);
141 fputs(" return val;\n"
142 "}\n"
143 "static uint64_t load64_align0(const uint8_t *ptr) {\n"
144 " uint64_t val;\n"
145 " memcpy(&val, ptr, sizeof(val));\n", out);
146 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
147 fputs(" return val;\n"
148 "}\n"
149 "static uint64_t load64_align1(const uint16_t *ptr) {\n"
150 " uint64_t val;\n"
151 " memcpy(&val, ptr, sizeof(val));\n", out);
152 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
153 fputs(" return val;\n"
154 "}\n"
155 "static uint64_t load64_align2(const uint32_t *ptr) {\n"
156 " uint64_t val;\n"
157 " memcpy(&val, ptr, sizeof(val));\n", out);
158 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
159 fputs(" return val;\n"
160 "}\n"
161 "static uint64_t load64_align3(const uint64_t *ptr) {\n"
162 " uint64_t val;\n"
163 " memcpy(&val, ptr, sizeof(val));\n", out);
164 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
165 fputs(" return val;\n"
166 "}\n"
167 "\n"
168 "static void store16_align0(uint8_t *ptr, uint16_t val) {\n", out);
169 if (is_big_endian) fputs(" val = i16_byteswap(val);", out);
170 fputs(" memcpy(ptr, &val, sizeof(val));\n"
171 "}\n"
172 "static void store16_align1(uint16_t *ptr, uint16_t val) {\n", out);
173 if (is_big_endian) fputs(" val = i16_byteswap(val);", out);
174 fputs(" memcpy(ptr, &val, sizeof(val));\n"
175 "}\n"
176 "static void store32_align0(uint8_t *ptr, uint32_t val) {\n", out);
177 if (is_big_endian) fputs(" val = i32_byteswap(val);", out);
178 fputs(" memcpy(ptr, &val, sizeof(val));\n"
179 "}\n"
180 "static void store32_align1(uint16_t *ptr, uint32_t val) {\n", out);
181 if (is_big_endian) fputs(" val = i32_byteswap(val);", out);
182 fputs(" memcpy(ptr, &val, sizeof(val));\n"
183 "}\n"
184 "static void store32_align2(uint32_t *ptr, uint32_t val) {\n", out);
185 if (is_big_endian) fputs(" val = i32_byteswap(val);", out);
186 fputs(" memcpy(ptr, &val, sizeof(val));\n"
187 "}\n"
188 "static void store64_align0(uint8_t *ptr, uint64_t val) {\n", out);
189 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
190 fputs(" memcpy(ptr, &val, sizeof(val));\n"
191 "}\n"
192 "static void store64_align1(uint16_t *ptr, uint64_t val) {\n", out);
193 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
194 fputs(" memcpy(ptr, &val, sizeof(val));\n"
195 "}\n"
196 "static void store64_align2(uint32_t *ptr, uint64_t val) {\n", out);
197 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
198 fputs(" memcpy(ptr, &val, sizeof(val));\n"
199 "}\n"
200 "static void store64_align3(uint64_t *ptr, uint64_t val) {\n", out);
201 if (is_big_endian) fputs(" val = i64_byteswap(val);", out);
202 fputs(" memcpy(ptr, &val, sizeof(val));\n"
203 "}\n"
98204 "\n"
99205 "static uint32_t i32_reinterpret_f32(const float src) {\n"
100206 " uint32_t dst;\n"
......@@ -912,18 +1018,9 @@ int main(int argc, char **argv) {
9121018 if (unreachable_depth == 0) {
9131019 uint32_t base = FuncGen_stackPop(&fg);
9141020 FuncGen_stackPush(&fg, out, WasmValType_i32);
915 if (align < 2 || isBigEndian) {
916 fseek(out, -1, SEEK_CUR);
917 fputc('\n', out);
918 for (uint8_t byte_i = 0; byte_i < 4; byte_i += 1) {
919 if (byte_i > 0) fputs(" |\n", out);
920 FuncGen_cont(&fg, out);
921 fprintf(out, "(uint32_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
922 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
923 }
924 } else fprintf(out, "*(const uint32_t *)&m%" PRIu32 "[l%" PRIu32
925 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
926 fputs(";\n", out);
1021 fprintf(out, "load32_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%" PRIu32
1022 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1023 align, 8 << align, 0, base, offset);
9271024 }
9281025 break;
9291026 }
......@@ -933,18 +1030,9 @@ int main(int argc, char **argv) {
9331030 if (unreachable_depth == 0) {
9341031 uint32_t base = FuncGen_stackPop(&fg);
9351032 FuncGen_stackPush(&fg, out, WasmValType_i64);
936 if (align < 3 || isBigEndian) {
937 fseek(out, -1, SEEK_CUR);
938 fputc('\n', out);
939 for (uint8_t byte_i = 0; byte_i < 8; byte_i += 1) {
940 if (byte_i > 0) fputs(" |\n", out);
941 FuncGen_cont(&fg, out);
942 fprintf(out, "(uint64_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
943 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
944 }
945 } else fprintf(out, "*(const uint64_t *)&m%" PRIu32 "[l%" PRIu32
946 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
947 fputs(";\n", out);
1033 fprintf(out, "load64_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%" PRIu32
1034 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1035 align, 8 << align, 0, base, offset);
9481036 }
9491037 break;
9501038 }
......@@ -954,18 +1042,9 @@ int main(int argc, char **argv) {
9541042 if (unreachable_depth == 0) {
9551043 uint32_t base = FuncGen_stackPop(&fg);
9561044 FuncGen_stackPush(&fg, out, WasmValType_f32);
957 if (align < 2 || isBigEndian) {
958 fputs("f32_reinterpret_i32(\n", out);
959 for (uint8_t byte_i = 0; byte_i < 4; byte_i += 1) {
960 if (byte_i > 0) fputs(" |\n", out);
961 FuncGen_cont(&fg, out);
962 fprintf(out, "(uint32_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
963 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
964 }
965 fputc(')', out);
966 } else fprintf(out, "*(const float *)&m%" PRIu32 "[l%" PRIu32
967 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
968 fputs(";\n", out);
1045 fprintf(out, "f32_reinterpret_i32(load32_align%" PRIu32 "((const uint%" PRIu32
1046 "_t *)&m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]));\n",
1047 align, 8 << align, 0, base, offset);
9691048 }
9701049 break;
9711050 }
......@@ -975,18 +1054,9 @@ int main(int argc, char **argv) {
9751054 if (unreachable_depth == 0) {
9761055 uint32_t base = FuncGen_stackPop(&fg);
9771056 FuncGen_stackPush(&fg, out, WasmValType_f64);
978 if (align < 3 || isBigEndian) {
979 fputs("f64_reinterpret_i64(\n", out);
980 for (uint8_t byte_i = 0; byte_i < 8; byte_i += 1) {
981 if (byte_i > 0) fputs(" |\n", out);
982 FuncGen_cont(&fg, out);
983 fprintf(out, "(uint64_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
984 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
985 }
986 fputc(')', out);
987 } else fprintf(out, "*(const double *)&m%" PRIu32 "[l%" PRIu32
988 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
989 fputs(";\n", out);
1057 fprintf(out, "f64_reinterpret_i64(load64_align%" PRIu32 "((const uint%" PRIu32
1058 "_t *)&m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]));\n",
1059 align, 8 << align, 0, base, offset);
9901060 }
9911061 break;
9921062 }
......@@ -1018,18 +1088,9 @@ int main(int argc, char **argv) {
10181088 if (unreachable_depth == 0) {
10191089 uint32_t base = FuncGen_stackPop(&fg);
10201090 FuncGen_stackPush(&fg, out, WasmValType_i32);
1021 if (align < 1 || isBigEndian) {
1022 fputs("(int16_t)(\n", out);
1023 for (uint8_t byte_i = 0; byte_i < 2; byte_i += 1) {
1024 if (byte_i > 0) fputs(" |\n", out);
1025 FuncGen_cont(&fg, out);
1026 fprintf(out, "(uint16_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
1027 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
1028 }
1029 fputc(')', out);
1030 } else fprintf(out, "*(const int16_t *)&m%" PRIu32 "[l%" PRIu32
1031 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
1032 fputs(";\n", out);
1091 fprintf(out, "(int16_t)load16_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%"
1092 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1093 align, 8 << align, 0, base, offset);
10331094 }
10341095 break;
10351096 }
......@@ -1039,18 +1100,9 @@ int main(int argc, char **argv) {
10391100 if (unreachable_depth == 0) {
10401101 uint32_t base = FuncGen_stackPop(&fg);
10411102 FuncGen_stackPush(&fg, out, WasmValType_i32);
1042 if (align < 1 || isBigEndian) {
1043 fseek(out, -1, SEEK_CUR);
1044 fputc('\n', out);
1045 for (uint8_t byte_i = 0; byte_i < 2; byte_i += 1) {
1046 if (byte_i > 0) fputs(" |\n", out);
1047 FuncGen_cont(&fg, out);
1048 fprintf(out, "(uint16_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
1049 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
1050 }
1051 } else fprintf(out, "*(const uint16_t *)&m%" PRIu32 "[l%" PRIu32
1052 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
1053 fputs(";\n", out);
1103 fprintf(out, "load16_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%"
1104 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1105 align, 8 << align, 0, base, offset);
10541106 }
10551107 break;
10561108 }
......@@ -1082,18 +1134,9 @@ int main(int argc, char **argv) {
10821134 if (unreachable_depth == 0) {
10831135 uint32_t base = FuncGen_stackPop(&fg);
10841136 FuncGen_stackPush(&fg, out, WasmValType_i64);
1085 if (align < 1 || isBigEndian) {
1086 fputs("(int16_t)(\n", out);
1087 for (uint8_t byte_i = 0; byte_i < 2; byte_i += 1) {
1088 if (byte_i > 0) fputs(" |\n", out);
1089 FuncGen_cont(&fg, out);
1090 fprintf(out, "(uint16_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
1091 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
1092 }
1093 fputc(')', out);
1094 } else fprintf(out, "*(const int16_t *)&m%" PRIu32 "[l%" PRIu32
1095 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
1096 fputs(";\n", out);
1137 fprintf(out, "(int16_t)load16_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%"
1138 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1139 align, 8 << align, 0, base, offset);
10971140 }
10981141 break;
10991142 }
......@@ -1103,18 +1146,9 @@ int main(int argc, char **argv) {
11031146 if (unreachable_depth == 0) {
11041147 uint32_t base = FuncGen_stackPop(&fg);
11051148 FuncGen_stackPush(&fg, out, WasmValType_i64);
1106 if (align < 1 || isBigEndian) {
1107 fseek(out, -1, SEEK_CUR);
1108 fputc('\n', out);
1109 for (uint8_t byte_i = 0; byte_i < 2; byte_i += 1) {
1110 if (byte_i > 0) fputs(" |\n", out);
1111 FuncGen_cont(&fg, out);
1112 fprintf(out, "(uint16_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
1113 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
1114 }
1115 } else fprintf(out, "*(const uint16_t *)&m%" PRIu32 "[l%" PRIu32
1116 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
1117 fputs(";\n", out);
1149 fprintf(out, "load16_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%"
1150 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1151 align, 8 << align, 0, base, offset);
11181152 }
11191153 break;
11201154 }
......@@ -1124,18 +1158,9 @@ int main(int argc, char **argv) {
11241158 if (unreachable_depth == 0) {
11251159 uint32_t base = FuncGen_stackPop(&fg);
11261160 FuncGen_stackPush(&fg, out, WasmValType_i64);
1127 if (align < 2 || isBigEndian) {
1128 fputs("(int32_t)(\n", out);
1129 for (uint8_t byte_i = 0; byte_i < 4; byte_i += 1) {
1130 if (byte_i > 0) fputs(" |\n", out);
1131 FuncGen_cont(&fg, out);
1132 fprintf(out, "(uint32_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
1133 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
1134 }
1135 fputc(')', out);
1136 } else fprintf(out, "*(const int32_t *)&m%" PRIu32 "[l%" PRIu32
1137 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
1138 fputs(";\n", out);
1161 fprintf(out, "(int32_t)load32_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%"
1162 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1163 align, 8 << align, 0, base, offset);
11391164 }
11401165 break;
11411166 }
......@@ -1145,18 +1170,9 @@ int main(int argc, char **argv) {
11451170 if (unreachable_depth == 0) {
11461171 uint32_t base = FuncGen_stackPop(&fg);
11471172 FuncGen_stackPush(&fg, out, WasmValType_i64);
1148 if (align < 2 || isBigEndian) {
1149 fseek(out, -1, SEEK_CUR);
1150 fputc('\n', out);
1151 for (uint8_t byte_i = 0; byte_i < 4; byte_i += 1) {
1152 if (byte_i > 0) fputs(" |\n", out);
1153 FuncGen_cont(&fg, out);
1154 fprintf(out, "(uint32_t)m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%"
1155 PRIu32 ")] << %2u", 0, base, offset + byte_i, byte_i << 3);
1156 }
1157 } else fprintf(out, "*(const uint32_t *)&m%" PRIu32 "[l%" PRIu32
1158 " + UINT32_C(%" PRIu32 ")]", 0, base, offset);
1159 fputs(";\n", out);
1173 fprintf(out, "load32_align%" PRIu32 "((const uint%" PRIu32 "_t *)&m%"
1174 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")]);\n",
1175 align, 8 << align, 0, base, offset);
11601176 }
11611177 break;
11621178 }
......@@ -1167,19 +1183,10 @@ int main(int argc, char **argv) {
11671183 if (unreachable_depth == 0) {
11681184 uint32_t value = FuncGen_stackPop(&fg);
11691185 uint32_t base = FuncGen_stackPop(&fg);
1170 if (align < 2 || isBigEndian) {
1171 for (uint8_t byte_i = 0; byte_i < 4; byte_i += 1) {
1172 FuncGen_indent(&fg, out);
1173 fprintf(out, "m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")] = "
1174 "(uint8_t)(l%" PRIu32 " >> %2u);\n",
1175 0, base, offset + byte_i, value, byte_i << 3);
1176 }
1177 } else {
1178 FuncGen_indent(&fg, out);
1179 fprintf(out, "*(uint32_t *)&m%" PRIu32 "[l%" PRIu32
1180 " + UINT32_C(%" PRIu32 ")] = l%" PRIu32 ";\n",
1181 0, base, offset, value);
1182 }
1186 FuncGen_indent(&fg, out);
1187 fprintf(out, "store32_align%" PRIu32 "((uint%" PRIu32 "_t *)&m%"
1188 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")], l%" PRIu32 ");\n",
1189 align, 8 << align, 0, base, offset, value);
11831190 }
11841191 break;
11851192 }
......@@ -1189,19 +1196,10 @@ int main(int argc, char **argv) {
11891196 if (unreachable_depth == 0) {
11901197 uint32_t value = FuncGen_stackPop(&fg);
11911198 uint32_t base = FuncGen_stackPop(&fg);
1192 if (align < 3 || isBigEndian) {
1193 for (uint8_t byte_i = 0; byte_i < 8; byte_i += 1) {
1194 FuncGen_indent(&fg, out);
1195 fprintf(out, "m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")] = "
1196 "(uint8_t)(l%" PRIu32 " >> %2u);\n",
1197 0, base, offset + byte_i, value, byte_i << 3);
1198 }
1199 } else {
1200 FuncGen_indent(&fg, out);
1201 fprintf(out, "*(uint64_t *)&m%" PRIu32 "[l%" PRIu32
1202 " + UINT32_C(%" PRIu32 ")] = l%" PRIu32 ";\n",
1203 0, base, offset, value);
1204 }
1199 FuncGen_indent(&fg, out);
1200 fprintf(out, "store64_align%" PRIu32 "((uint%" PRIu32 "_t *)&m%"
1201 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")], l%" PRIu32 ");\n",
1202 align, 8 << align, 0, base, offset, value);
12051203 }
12061204 break;
12071205 }
......@@ -1211,19 +1209,11 @@ int main(int argc, char **argv) {
12111209 if (unreachable_depth == 0) {
12121210 uint32_t value = FuncGen_stackPop(&fg);
12131211 uint32_t base = FuncGen_stackPop(&fg);
1214 if (align < 2 || isBigEndian) {
1215 for (uint8_t byte_i = 0; byte_i < 4; byte_i += 1) {
1216 FuncGen_indent(&fg, out);
1217 fprintf(out, "m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")] = "
1218 "(uint8_t)(i32_reinterpret_f32(l%" PRIu32 ") >> %2u);\n",
1219 0, base, offset + byte_i, value, byte_i << 3);
1220 }
1221 } else {
1222 FuncGen_indent(&fg, out);
1223 fprintf(out, "*(float *)&m%" PRIu32 "[l%" PRIu32
1224 " + UINT32_C(%" PRIu32 ")] = l%" PRIu32 ";\n",
1225 0, base, offset, value);
1226 }
1212 FuncGen_indent(&fg, out);
1213 fprintf(out, "store32_align%" PRIu32 "((uint%" PRIu32 "_t *)&m%"
1214 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")], "
1215 "i32_reinterpret_f32(l%" PRIu32 "));\n",
1216 align, 8 << align, 0, base, offset, value);
12271217 }
12281218 break;
12291219 }
......@@ -1233,19 +1223,11 @@ int main(int argc, char **argv) {
12331223 if (unreachable_depth == 0) {
12341224 uint32_t value = FuncGen_stackPop(&fg);
12351225 uint32_t base = FuncGen_stackPop(&fg);
1236 if (align < 3 || isBigEndian) {
1237 for (uint8_t byte_i = 0; byte_i < 8; byte_i += 1) {
1238 FuncGen_indent(&fg, out);
1239 fprintf(out, "m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")] = "
1240 "(uint8_t)(i64_reinterpret_f64(l%" PRIu32 ") >> %2u);\n",
1241 0, base, offset + byte_i, value, byte_i << 3);
1242 }
1243 } else {
1244 FuncGen_indent(&fg, out);
1245 fprintf(out, "*(double *)&m%" PRIu32 "[l%" PRIu32
1246 " + UINT32_C(%" PRIu32 ")] = l%" PRIu32 ";\n",
1247 0, base, offset, value);
1248 }
1226 FuncGen_indent(&fg, out);
1227 fprintf(out, "store64_align%" PRIu32 "((uint%" PRIu32 "_t *)&m%"
1228 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")], "
1229 "i64_reinterpret_f64(l%" PRIu32 "));\n",
1230 align, 8 << align, 0, base, offset, value);
12491231 }
12501232 break;
12511233 }
......@@ -1267,19 +1249,11 @@ int main(int argc, char **argv) {
12671249 if (unreachable_depth == 0) {
12681250 uint32_t value = FuncGen_stackPop(&fg);
12691251 uint32_t base = FuncGen_stackPop(&fg);
1270 if (align < 1 || isBigEndian) {
1271 for (uint8_t byte_i = 0; byte_i < 2; byte_i += 1) {
1272 FuncGen_indent(&fg, out);
1273 fprintf(out, "m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")] = "
1274 "(uint8_t)(l%" PRIu32 " >> %2u);\n",
1275 0, base, offset + byte_i, value, byte_i << 3);
1276 }
1277 } else {
1278 FuncGen_indent(&fg, out);
1279 fprintf(out, "*(uint16_t *)&m%" PRIu32 "[l%" PRIu32
1280 " + UINT32_C(%" PRIu32 ")] = (uint16_t)l%" PRIu32 ";\n",
1281 0, base, offset, value);
1282 }
1252 FuncGen_indent(&fg, out);
1253 fprintf(out, "store16_align%" PRIu32 "((uint%" PRIu32 "_t *)&m%"
1254 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")], "
1255 "(uint16_t)l%" PRIu32 ");\n",
1256 align, 8 << align, 0, base, offset, value);
12831257 }
12841258 break;
12851259 }
......@@ -1301,19 +1275,11 @@ int main(int argc, char **argv) {
13011275 if (unreachable_depth == 0) {
13021276 uint32_t value = FuncGen_stackPop(&fg);
13031277 uint32_t base = FuncGen_stackPop(&fg);
1304 if (align < 1 || isBigEndian) {
1305 for (uint8_t byte_i = 0; byte_i < 2; byte_i += 1) {
1306 FuncGen_indent(&fg, out);
1307 fprintf(out, "m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")] = "
1308 "(uint8_t)(l%" PRIu32 " >> %2u);\n",
1309 0, base, offset + byte_i, value, byte_i << 3);
1310 }
1311 } else {
1312 FuncGen_indent(&fg, out);
1313 fprintf(out, "*(uint16_t *)&m%" PRIu32 "[l%" PRIu32
1314 " + UINT32_C(%" PRIu32 ")] = (uint16_t)l%" PRIu32 ";\n",
1315 0, base, offset, value);
1316 }
1278 FuncGen_indent(&fg, out);
1279 fprintf(out, "store16_align%" PRIu32 "((uint%" PRIu32 "_t *)&m%"
1280 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")], "
1281 "(uint16_t)l%" PRIu32 ");\n",
1282 align, 8 << align, 0, base, offset, value);
13171283 }
13181284 break;
13191285 }
......@@ -1323,19 +1289,11 @@ int main(int argc, char **argv) {
13231289 if (unreachable_depth == 0) {
13241290 uint32_t value = FuncGen_stackPop(&fg);
13251291 uint32_t base = FuncGen_stackPop(&fg);
1326 if (align < 2 || isBigEndian) {
1327 for (uint8_t byte_i = 0; byte_i < 4; byte_i += 1) {
1328 FuncGen_indent(&fg, out);
1329 fprintf(out, "m%" PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")] = "
1330 "(uint8_t)(l%" PRIu32 " >> %2u);\n",
1331 0, base, offset + byte_i, value, byte_i << 3);
1332 }
1333 } else {
1334 FuncGen_indent(&fg, out);
1335 fprintf(out, "*(uint32_t *)&m%" PRIu32 "[l%" PRIu32
1336 " + UINT32_C(%" PRIu32 ")] = (uint32_t)l%" PRIu32 ";\n",
1337 0, base, offset, value);
1338 }
1292 FuncGen_indent(&fg, out);
1293 fprintf(out, "store32_align%" PRIu32 "((uint%" PRIu32 "_t *)&m%"
1294 PRIu32 "[l%" PRIu32 " + UINT32_C(%" PRIu32 ")], "
1295 "(uint32_t)l%" PRIu32 ");\n",
1296 align, 8 << align, 0, base, offset, value);
13391297 }
13401298 break;
13411299 }