Skip to content

Commit

Permalink
Merge SVN 4979
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Sep 26, 2024
1 parent 244735c commit 88bce9a
Show file tree
Hide file tree
Showing 13 changed files with 2,968 additions and 127 deletions.
20 changes: 20 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@
* pplex.l (ppcopy_find_file, ppcopy): replace slash to match system and
always place name in buffer to allow this

2023-02-07 Simon Sobisch <[email protected]>

* typeck.c (cb_build_optim_cond): generate cob_bcd_cmp call for COMP-3/COMP-6
* typeck.c (cb_build_optim_cond). codeoptim.def, codeoptim.c, codegen.c:
disabled "local" functions for COB_CMP_PACKED_INT, COB_GET_PACKED_INT,
COB_GET_PACKED_INT64 as the updated libcob variants are not slower, so
generate calls to these instead

2023-02-03 Simon Sobisch <[email protected]>

* typeck.c (cb_build_optim_add), codeoptim.def, codeoptim.c, codegen.c:
added COB_GET_PACKED_INT64, COB_ADD_PACKED_INT64 for fast-resolving/
adding PACKED-DECIMAL fields with 9-18 digits
* typeck.c (cb_build_optim_sub), codegen.c, tree.h
(CB_CAST_NEGATIVE_INTEGER, CB_CAST_NEGATIVE_LONG_INT): wrap subtractions
on PACKED-DECIMAL fields in a negative value used with optimized
packed_add
* typeck.c (cb_check_num_cond, cb_build_optim_cond): generate memcmp for
COMP-6 fields with same scale

2023-02-01 Simon Sobisch <[email protected]>

* parser.y (rep_name_list): fixed error handling loop
Expand Down
38 changes: 30 additions & 8 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3546,14 +3546,6 @@ output_integer (cb_tree x)
}
break;

case CB_USAGE_PACKED:
if (f->pic->scale == 0 && f->pic->digits < 10) {
optimize_defs[COB_GET_PACKED_INT] = 1;
output_func_1 ("cob_get_packed_int", x);
return;
}
break;

case CB_USAGE_BINARY:
case CB_USAGE_COMP_5:
case CB_USAGE_COMP_X:
Expand Down Expand Up @@ -3663,6 +3655,16 @@ output_integer (cb_tree x)
}
break;

#if 0 /* libcob's optimized version is not slower, so drop that */
case CB_USAGE_PACKED:
if (f->pic->scale == 0 && f->pic->digits < 10) {
optimize_defs[COB_GET_PACKED_INT] = 1;
output_func_1 ("cob_get_packed_int", x);
return;
}
break;
#endif

default:
break;
}
Expand Down Expand Up @@ -3905,6 +3907,16 @@ output_long_integer (cb_tree x)
}
break;

#if 0 /* libcob's optimized version is not slower, so drop that */
case CB_USAGE_PACKED:
if (f->pic->scale == 0 && f->pic->digits < 19) {
optimize_defs[COB_GET_PACKED_INT64] = 1;
output_func_1 ("cob_get_packed_int64", x);
return;
}
break;
#endif

default:
break;
}
Expand Down Expand Up @@ -4151,6 +4163,16 @@ output_param (cb_tree x, int id)
case CB_CAST_PROGRAM_POINTER:
output_param (cp->val, id);
break;
case CB_CAST_NEGATIVE_INTEGER:
output ("-(");
output_integer (cp->val);
output (")");
break;
case CB_CAST_NEGATIVE_LONG_INT:
output ("-(");
output_long_integer (cp->val);
output (")");
break;
default:
break;
}
Expand Down
78 changes: 74 additions & 4 deletions cobc/codeoptim.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ cob_gen_optim (const enum cb_optim val)
output_storage ("}");
return;

#if 0 /* libcob's optimized version is not slower, so drop that */
case COB_CMP_PACKED_INT:
output_storage ("static int COB_NOINLINE");
output_storage ("cob_cmp_packed_int (const cob_field *f, const cob_s64_t n)");
Expand All @@ -328,8 +329,8 @@ cob_gen_optim (const enum cb_optim val)
output_storage (" val = val * 10");
output_storage (" + (*p++ & 0x0f);");
output_storage (" }");
output_storage (" val *= 10;");
output_storage (" val += *p >> 4;");
output_storage (" val = val * 10");
output_storage (" + (*p >> 4);");
output_storage (" if ((*p & 0x0f) == 0x0d) {");
output_storage (" val = -val;");
output_storage (" }");
Expand All @@ -351,15 +352,39 @@ cob_gen_optim (const enum cb_optim val)
output_storage (" val = val * 10");
output_storage (" + (*p++ & 0x0f);");
output_storage (" }");
output_storage (" val *= 10;");
output_storage (" val += *p >> 4;");
output_storage (" val = val * 10");
output_storage (" + (*p >> 4);");
output_storage (" if ((*p & 0x0f) == 0x0d) {");
output_storage (" val = -val;");
output_storage (" }");
output_storage (" return val;");
output_storage ("}");
return;

case COB_GET_PACKED_INT64:
output_storage ("static cob_s64_t COB_NOINLINE");
output_storage ("cob_get_packed_int64 (const cob_field *f)");
output_storage ("{");
output_storage (" register unsigned char *p = f->data;");
output_storage (" const register unsigned char *p_end = p + f->size - 1;");
output_storage (" register cob_s64_t val = 0;");

output_storage (" while (p < p_end) {");
output_storage (" val = val * 10");
output_storage (" + (*p >> 4);");
output_storage (" val = val * 10");
output_storage (" + (*p++ & 0x0f);");
output_storage (" }");
output_storage (" val = val * 10");
output_storage (" + (*p >> 4);");
output_storage (" if ((*p & 0x0f) == 0x0d) {");
output_storage (" val = -val;");
output_storage (" }");
output_storage (" return val;");
output_storage ("}");
return;
#endif

case COB_ADD_PACKED_INT:
output_storage ("static int COB_NOINLINE");
output_storage ("cob_add_packed_int (cob_field *f, const int val)");
Expand Down Expand Up @@ -405,6 +430,51 @@ cob_gen_optim (const enum cb_optim val)
output_storage ("}");
return;

case COB_ADD_PACKED_INT64:
output_storage ("static int COB_NOINLINE");
output_storage ("cob_add_packed_int64 (cob_field *f, const cob_s64_t val)");
output_storage ("{");
output_storage (" register unsigned char *p;");
output_storage (" size_t size;");
output_storage (" cob_s64_t carry = 0;");
output_storage (" cob_s64_t n;");
output_storage (" cob_s64_t inc;");

output_storage (" if (val == 0) {");
output_storage (" return 0;");
output_storage (" }");
output_storage (" p = f->data + f->size - 1;");
output_storage (" if ((*p & 0x0f) == 0x0d) {");
output_storage (" if (val > 0) {");
output_storage (" return cob_add_int (f, val, 0);");
output_storage (" }");
output_storage (" n = -val;");
output_storage (" } else {");
output_storage (" if (val < 0) {");
output_storage (" return cob_add_int (f, val, 0);");
output_storage (" }");
output_storage (" n = val;");
output_storage (" }");
output_storage (" inc = (*p >> 4) + (n %% 10);");
output_storage (" n /= 10;");
output_storage (" carry = inc / 10;");
output_storage (" *p = ((inc %% 10) << 4) | (*p & 0x0f);");
output_storage (" p--;");

output_storage (" for (size = 0; size < f->size - 1; ++size, --p) {");
output_storage (" if (!carry && !n) {");
output_storage (" break;");
output_storage (" }");
output_storage (" inc = ((*p >> 4) * 10) + (*p & 0x0f) + carry + (n %% 100);");
output_storage (" carry = inc / 100;");
output_storage (" n /= 100;");
output_storage (" inc %%= 100;");
output_storage (" *p = ((inc / 10) << 4) | (inc %% 10);");
output_storage (" }");
output_storage (" return 0;");
output_storage ("}");
return;

/* Aligned variants */

/* Aligned compares */
Expand Down
9 changes: 8 additions & 1 deletion cobc/codeoptim.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2009-2013, 2018-2021 Free Software Foundation, Inc.
Copyright (C) 2009-2013, 2018-2021,2023 Free Software Foundation, Inc.
Written by Roger While, Ron Norman

This file is part of GnuCOBOL.
Expand Down Expand Up @@ -34,9 +34,16 @@ CB_OPTIM_DEF (COB_NOP)

CB_OPTIM_DEF (COB_POINTER_MANIP)
CB_OPTIM_DEF (COB_GET_NUMDISP)
#if 0 /* libcob's optimized version is not slower, so drop that */
CB_OPTIM_DEF (COB_CMP_PACKED_INT)
CB_OPTIM_DEF (COB_GET_PACKED_INT)
CB_OPTIM_DEF (COB_GET_PACKED_INT64)
#endif

/* note: the additions are also used for substract by wrapping
the second part in -(x) */
CB_OPTIM_DEF (COB_ADD_PACKED_INT)
CB_OPTIM_DEF (COB_ADD_PACKED_INT64)

CB_OPTIM_DEF (COB_CMP_ALIGN_U16)
CB_OPTIM_DEF (COB_CMP_ALIGN_S16)
Expand Down
12 changes: 7 additions & 5 deletions cobc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,13 @@ enum cb_usage {
/* Cast type */
enum cb_cast_type {
CB_CAST_INTEGER = 0, /* 0 */
CB_CAST_LONG_INT, /* 1 */
CB_CAST_ADDRESS, /* 2 */
CB_CAST_ADDR_OF_ADDR, /* 3 */
CB_CAST_LENGTH, /* 4 */
CB_CAST_PROGRAM_POINTER /* 5 */
CB_CAST_NEGATIVE_INTEGER, /* 1 */
CB_CAST_LONG_INT, /* 2 */
CB_CAST_NEGATIVE_LONG_INT, /* 3 */
CB_CAST_ADDRESS, /* 4 */
CB_CAST_ADDR_OF_ADDR, /* 5 */
CB_CAST_LENGTH, /* 6 */
CB_CAST_PROGRAM_POINTER /* 7 */
};

/* Intrinsic functions */
Expand Down
Loading

0 comments on commit 88bce9a

Please sign in to comment.