Skip to content

Commit 9bb5fd0

Browse files
author
Y_Less
committed
Use __COMPILER_CELL_SHIFT instead of cellbytes in a lot of places.
1 parent b122e38 commit 9bb5fd0

File tree

10 files changed

+40
-23
lines changed

10 files changed

+40
-23
lines changed

YSI_Coding/y_inline/y_inline_impl2.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static stock Inline_FoundDescriptor(size, data[E_INLINE_DATA])
414414
}
415415
default:
416416
{
417-
data[E_INLINE_DATA_PARAMETERS][data[E_INLINE_DATA_PARAMETER_COUNT]++] = size * cellbytes;
417+
data[E_INLINE_DATA_PARAMETERS][data[E_INLINE_DATA_PARAMETER_COUNT]++] = size << __COMPILER_CELL_SHIFT;
418418
data[E_INLINE_DATA_STATE] |= 8;
419419
}
420420
}
@@ -1174,7 +1174,7 @@ static stock Callback_InlineByName(const name[], tag)
11741174
frm = ptr + AMX_Read(ret + cellbytes),
11751175
args = Inline_NumArgs(frm),
11761176
size = frm - ptr + 12 + args,
1177-
Alloc:closure = malloc(size / cellbytes + _:E_INLINE_CALL - 1);
1177+
Alloc:closure = malloc((size >>> __COMPILER_CELL_SHIFT) + (_:E_INLINE_CALL - 1));
11781178
if (!closure)
11791179
return 0;
11801180
mset(closure, _:E_INLINE_CALL_NULL, 0);
@@ -1676,7 +1676,7 @@ static stock Inline_GenerateLocalsStore(ctx[AsmContext], const parameters[], cou
16761676
@emit STACK accumulate
16771677
accumulate = 0;
16781678
@emit POP.alt
1679-
@emit SREF.S.alt count * cellbytes + 12
1679+
@emit SREF.S.alt (count << __COMPILER_CELL_SHIFT) + 12
16801680
}
16811681
case 0:
16821682
accumulate += cellbytes;
@@ -1962,7 +1962,7 @@ stock Inline_UI_(const &header)
19621962
// storage. The other option would be allocating it separately later
19631963
// when we determine it is needed, but that would be no faster in the
19641964
// common case, and slower in the uncommon case, so just do it together.
1965-
Alloc:closure = malloc(size / cellbytes + _:E_INLINE_CALL - 1);
1965+
Alloc:closure = malloc((size >>> __COMPILER_CELL_SHIFT) + (_:E_INLINE_CALL - 1));
19661966
P:5("Inline_UI_: %d %d %d %d %d", ptr, frm, size, _:closure, AMX_Read(header));
19671967
if (!closure)
19681968
return 0;

YSI_Coding/y_va/y_va_impl.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static stock YVA2_CodeGenDeepCleanup(ctx[AsmContext], depth, returningString)
319319
if (returningString)
320320
@emit POP.pri
321321
// Remove all the temporary storage locations.
322-
@emit STACK depth * cellbytes
322+
@emit STACK (depth << __COMPILER_CELL_SHIFT)
323323
}
324324

325325
static stock YVA2_CodeGenPushVariable(ctx[AsmContext], stack)
@@ -387,7 +387,7 @@ static stock YVA2_FoundCall(const m[CodeScanner])
387387
new
388388
dest = YSI_g_sContexts[pos][AsmContext_buffer];
389389
// First, rewrite the `___` call-site to call `YVA2_DoPush` instead.
390-
YVA2_CodeGenPushSite(YSI_g_sContexts[pos], hole, YSI_g_sSkips[pos], -YSI_g_sStacks[0] - pos * cellbytes), // YSI_g_sStacks[0]!!!
390+
YVA2_CodeGenPushSite(YSI_g_sContexts[pos], hole, YSI_g_sSkips[pos], -YSI_g_sStacks[0] - (pos << __COMPILER_CELL_SHIFT)), // YSI_g_sStacks[0]!!!
391391
// Shift the code up.
392392
YVA2_CodeGenShiftCode(
393393
dest + YSI_g_sContexts[pos][AsmContext_buffer_offset],
@@ -398,7 +398,7 @@ static stock YVA2_FoundCall(const m[CodeScanner])
398398
YSI_g_sContexts[pos][AsmContext_buffer_offset] = (end - dest) - (YSI_g_sLength[pos] - codeLength + returningString) - 16;
399399
if (len == 24)
400400
YSI_g_sContexts[pos][AsmContext_buffer_offset] -= 8;
401-
YVA2_CodeGenPushVariable(YSI_g_sContexts[pos], -YSI_g_sStacks[0] - pos * cellbytes);
401+
YVA2_CodeGenPushVariable(YSI_g_sContexts[pos], -YSI_g_sStacks[0] - (pos << __COMPILER_CELL_SHIFT));
402402
YSI_g_sContexts[pos][AsmContext_buffer_offset] += 8;
403403
if (returningString == 12)
404404
YSI_g_sContexts[pos][AsmContext_buffer_offset] += 8;

YSI_Core/y_core/y_compilerdata.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,23 @@ const __CompilerDefault:__COMPILER_DEFAULT = __CompilerDefault:0;
543543
#error YSI assumes `charbits` is 8.
544544
#endif
545545
546+
#define __COMPILER_CELL_BYTES cellbytes
547+
#define __COMPILER_CELL_BITS cellbits
548+
#define __COMPILER_CHAR_BITS charbits
549+
550+
// How much to adjust a cellcount by to get a byte count.
551+
#if cellbits == 8
552+
#define __COMPILER_CELL_SHIFT (0)
553+
#elseif cellbits == 16
554+
#define __COMPILER_CELL_SHIFT (1)
555+
#elseif cellbits == 32
556+
#define __COMPILER_CELL_SHIFT (2)
557+
#elseif cellbits == 64
558+
#define __COMPILER_CELL_SHIFT (3)
559+
#else
560+
#error Unknown cellbits size.
561+
#endif
562+
546563
#define FUNCTION_LENGTH (__COMPILER_sNAMEMAX + 1)
547564
548565
#if defined _INC_indirection

YSI_Core/y_core/y_debug_impl.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ native Debug_PrintQ_PRINT(const str[], const expr[], &Debug_PrintQ_SIZEOF:size,
729729
static stock bool:Debug_IsStringLike(addr, len = 256)
730730
{
731731
new i = 0;
732-
len *= cellbytes;
732+
len = len << __COMPILER_CELL_SHIFT;
733733
for (i = 0; i != len; i += cellbytes)
734734
{
735735
new ch = AMX_Read(addr + i);

YSI_Core/y_core/y_scriptinit_impl.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ stock Server_PrintIntroMessage(...)
418418
// Header.
419419
YSI_Print(YSI_gscSpacer);
420420
// Body.
421-
for (new i = 3 * cellbytes, j = 3 * cellbytes + numargs() * cellbytes, a = 0; i != j; i += cellbytes)
421+
for (new i = 3 * cellbytes, j = (numargs() << __COMPILER_CELL_SHIFT) + (3 * cellbytes), a = 0; i != j; i += cellbytes)
422422
{
423423
#emit LCTRL 5
424424
#emit LOAD.S.alt i
@@ -466,7 +466,7 @@ stock Server_PrintIntroPart(...)
466466
YSI_Print(YSI_gscSpacer);
467467
}
468468
// Body.
469-
for (new i = 3 * cellbytes, j = 3 * cellbytes + numargs() * cellbytes, a = 0; i != j; i += cellbytes)
469+
for (new i = 3 * cellbytes, j = 3 * cellbytes + (numargs() << __COMPILER_CELL_SHIFT), a = 0; i != j; i += cellbytes)
470470
{
471471
#emit LCTRL 5
472472
#emit LOAD.S.alt i

YSI_Core/y_core/y_utils_impl.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ stock Base64Encode(dest[], const src[], num = sizeof (src), len = sizeof (dest),
12571257
sEncoding[65 char] = !"DCBAHGFELKJIPONMTSRQXWVUbaZYfedcjihgnmlkrqpovutszyxw32107654/+98",
12581258
//tmp,
12591259
ret = 0;
1260-
num *= cellbytes;
1260+
num = num << __COMPILER_CELL_SHIFT;
12611261
if (len <= ceildiv(num, 3))
12621262
{
12631263
// How many complete chunks can we fit in?
@@ -1449,9 +1449,9 @@ stock Base64Decode(dest[], const src[], len = sizeof (dest), offset = 0)
14491449
num = 0;
14501450
// Work out the final length. Subtract some for incomplete bytes and
14511451
// insufficient destination data.
1452-
num = strlen(src);
1453-
len *= cellbytes;
1454-
blocks = num / cellbytes;
1452+
num = strlen(src),
1453+
len = len << __COMPILER_CELL_SHIFT,
1454+
blocks = num >>> __COMPILER_CELL_SHIFT;
14551455
if (src{num - 1} == '=')
14561456
{
14571457
--blocks;
@@ -3022,7 +3022,7 @@ stock bool:Files_CopyRange(File:i, end, const string:dst[])
30223022
// Must start at the start...
30233023
new
30243024
File:o = fopen(dst, io_write),
3025-
count = min(YSI_UNSAFE_HUGE_LENGTH, end / cellbytes);
3025+
count = min(YSI_UNSAFE_HUGE_LENGTH, end >>> __COMPILER_CELL_SHIFT);
30263026
if (!o)
30273027
{
30283028
return false;

YSI_Data/y_jaggedarray/y_jaggedarray_impl.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ stock bool:_Jagged_Move(array[][], size1, size2, ...)
407407
stock _Jagged_Empty(array[][], size1, size2)
408408
{
409409
// The size of the main storage area, including the header.
410-
size2 = (size1 + size1 * size2) * cellbytes;
410+
size2 = (size1 * size2 + size1) << __COMPILER_CELL_SHIFT;
411411
while (--size1)
412412
{
413413
#emit LOAD.S.pri array

YSI_Data/y_sortedarray/y_sortedarray_entry.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ stock bool:_Sorted_Add(arr[], &size, value, max = sizeof (arr))
215215
else if (arr[0] >= value)
216216
{
217217
// New smallest value.
218-
memcpy(arr[1], arr[0], 0, size * cellbytes, max - 1);
218+
memcpy(arr[1], arr[0], 0, size << __COMPILER_CELL_SHIFT, max - 1);
219219
arr[0] = value;
220220
}
221221
else
222222
{
223223
new idx = _Sorted_FindInsert(arr, size, value);
224-
memcpy(arr[idx + 1], arr[idx], 0, (size - idx) * cellbytes, max - idx - 1);
224+
memcpy(arr[idx + 1], arr[idx], 0, (size - idx) << __COMPILER_CELL_SHIFT, max - idx - 1);
225225
arr[idx] = value;
226226
}
227227
++size;
@@ -254,7 +254,7 @@ stock bool:_Sorted_Remove(arr[], &size, value)
254254
return true;
255255
}
256256
// We are shrinking the array, so the destination size doesn't matter.
257-
memcpy(arr[idx], arr[idx + 1], 0, (size - idx) * cellbytes, cellmax);
257+
memcpy(arr[idx], arr[idx + 1], 0, (size - idx) << __COMPILER_CELL_SHIFT, cellmax);
258258
return true;
259259
}
260260
#define Sorted_Remove SORTED_FUNC_N<Sorted_Remove>

YSI_Storage/y_bitmap/y_bitmap_read.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ static stock bool:Bitmap_ReadHeader(File:bmp, &x, &y)
110110
native Bitmap_FBlockReadAddr(File:file, addr, size) = fblockread;
111111
native Bitmap_FBlockReadRef(File:file, &ref, size) = fblockread;
112112

113-
#define BITMAP_TO_32(%0) ((%0) * cellbytes)
113+
#define BITMAP_TO_32(%0) ((%0) * 4)
114114
#define BITMAP_TO_24(%0) ((%0) * 3) // * 3 / BITMAP_TO_32(4), cancels.
115115

116116
static stock bool:Bitmap_ReadBody(Bitmap:ctx, File:bmp)
117117
{
118118
// Allocate the memory for the main input. We don't need to use `CEILDIV`
119119
// here because the BMP file format body is always an exact multiple of 4.
120120
new
121-
width = Bitmap_Width(ctx) * cellbytes,
121+
width = Bitmap_Width(ctx) << __COMPILER_CELL_SHIFT,
122122
size = ceildiv(width * 3, 4 * cellbytes),
123123
Alloc:input = malloc(size);
124124
if (!input)
@@ -129,7 +129,7 @@ static stock bool:Bitmap_ReadBody(Bitmap:ctx, File:bmp)
129129

130130
new
131131
y = Bitmap_Height(ctx),
132-
dest = _:ctx * cellbytes + y * width;
132+
dest = (_:ctx << __COMPILER_CELL_SHIFT) + y * width;
133133
#emit CONST.pri YSI_gMallocMemory
134134
#emit LOAD.S.alt dest
135135
#emit ADD

YSI_Storage/y_xml/y_xml_entry.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ stock XML_Parse(XML:rule, const filename[])
249249
// use this as a handy break point for long lines.
250250
++pos;
251251
lineOffset = sizeof (line) - 1 - pos;
252-
memcpy(line, line[pos], 0, lineOffset * cellbytes);
252+
memcpy(line, line[pos], 0, lineOffset << __COMPILER_CELL_SHIFT);
253253
break;
254254
}
255255
++pos;

0 commit comments

Comments
 (0)