00001
00013 #ifndef C4E_ELEMENTS_H
00014 #define C4E_ELEMENTS_H
00015
00016
00017
00018
00019 #include "c4e_sys.h"
00020
00021
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025
00026
00027
00028
00029
00030
00031
00032
00040 typedef struct
00041 {
00045 C4eArchIdx size;
00046
00050 C4eArchDigit* digits;
00051 } C4eElement;
00052
00053
00054
00058 typedef enum
00059 {
00060 C4eElemCmpEQ,
00061 C4eElemCmpLT,
00062 C4eElemCmpGT
00063 } C4eElemCmp;
00064
00065
00070 typedef struct
00071 {
00072 C4eElement val;
00073 C4eArchSize len;
00074 } C4eElemOsp;
00075
00076
00080 typedef struct
00081 {
00082 C4eElement x;
00083 C4eElement y;
00084 C4eArchUint attr;
00085 } C4eElemPair;
00086
00087
00093 typedef struct
00094 {
00095 C4eElement x;
00096 C4eElement y;
00097 C4eElement z;
00098 C4eArchUint attr;
00099 } C4eElemTriple;
00100
00101
00102
00103
00104
00105
00106
00107
00119 #define C4E_ELEM_ASGN_MEM(elem, digmem) \
00120 ((elem)->digits = (digmem))
00121
00122
00123
00133 #define C4E_ELEM_DIGITS_NUM(bytes) \
00134 C4E_SYS_CAST(C4eArchIdx, C4E_SYS_DIV_CEIL((bytes), C4E_ARCH_DIGIT_SIZE))
00135
00136
00137
00151 #define C4E_ELEM_IS_ZERO(x) ((x)->size == 0U)
00152
00153
00154
00155
00169 #define C4E_ELEM_IS_NZERO(x) (!C4E_ELEM_IS_ZERO(x))
00170
00171
00172
00173
00180 #define C4E_ELEM_SET_ZERO(x) ((x)->size = 0U)
00181
00182
00183
00196 #define C4E_ELEM_IS_ONE(x) (((x)->size == 1U) && \
00197 ((x)->digits[0] == C4E_SYS_DIGIT_ONE))
00198
00199
00200
00207 #define C4E_ELEM_SET_ONE(x) \
00208 do \
00209 { \
00210 (x)->digits[0] = C4E_SYS_DIGIT_ONE; \
00211 (x)->size = 1U; \
00212 } while (C4E_FALSE)
00213
00214
00215
00229 #define C4E_ELEM_IS_EVEN(elem) \
00230 (((elem)->digits[0] & C4E_SYS_DIGIT_ONE) == C4E_SYS_DIGIT_ZERO)
00231
00232
00233
00234
00248 #define C4E_ELEM_IS_ODD(elem) (!C4E_ELEM_IS_EVEN(elem))
00249
00250
00251
00261 #define C4E_ELEM_IS_NORM(x) \
00262 (C4E_ELEM_IS_ZERO(x) || \
00263 ((x)->digits[(x)->size - 1U] != C4E_SYS_DIGIT_ZERO))
00264
00265
00266
00267
00277 #define C4E_ELEM_MUL2(x) c4e_elem_bits_shl((x), 1U)
00278
00279
00280
00281
00291 #define C4E_ELEM_DIV2(x) c4e_elem_bits_shr((x), 1U)
00292
00293
00294
00295
00303 #define C4E_ELEM_ASSERT_IN(x) \
00304 C4E_ASSERT(((x) != NULL) && (C4E_ELEM_IS_ZERO(x) || ((x)->digits != NULL)))
00305
00306
00307
00316 #define C4E_ELEM_ASSERT_PTR(x) \
00317 C4E_ASSERT(((x) != NULL) && ((x)->digits != NULL))
00318
00319
00320
00321
00329 #define C4E_ELEM_ASSERT_NORM(x) C4E_ASSERT(C4E_ELEM_IS_NORM(x))
00330
00331
00332
00333
00341 #define C4E_ELEM_ASSERT_NZERO(x) \
00342 C4E_ASSERT(C4E_ELEM_IS_NZERO(x))
00343
00344
00345
00346
00347
00348
00349
00350
00351
00366 C4eArchDigit c4e_elem_msb(C4E_CONST C4eElement* x);
00367
00368
00369
00386 C4eArchSize c4e_elem_bits(C4E_CONST C4eElement* x);
00387
00388
00389
00398 void c4e_elem_norm(C4eElement* x);
00399
00400
00401
00410 void c4e_elem_cpy(C4E_CONST C4eElement* C4E_RESTRICT src,
00411 C4eElement* C4E_RESTRICT dst);
00412
00413
00414
00426 void c4e_elem_swap(C4eElement* C4E_RESTRICT elem1,
00427 C4eElement* C4E_RESTRICT elem2);
00428
00429
00430
00446 void c4e_elem_fill(C4E_CONST C4eElement* x, C4eArchDigit digit);
00447
00448
00449
00465 C4eSysStatus c4e_elem_rand(C4eElement* x);
00466
00467
00468
00480 void c4e_elem_digits_shl(C4eElement* x, C4eArchIdx shift);
00481
00482
00483
00496 void c4e_elem_bits_shl(C4eElement* x, C4eArchUint shift);
00497
00498
00499
00509 void c4e_elem_shl(C4eElement* x, C4eArchSize shift);
00510
00511
00512
00513
00523 void c4e_elem_digits_shr(C4eElement* x, C4eArchIdx shift);
00524
00525
00526
00539 void c4e_elem_bits_shr(C4eElement* x, C4eArchUint shift);
00540
00541
00542
00552 void c4e_elem_shr(C4eElement* x, C4eArchSize shift);
00553
00554
00555
00592 void c4e_elem_os2e(C4E_CONST C4eArchUint8* C4E_RESTRICT osp, C4eArchSize len,
00593 C4eElement* C4E_RESTRICT elem);
00594
00595
00596
00642 C4eArchSize c4e_elem_e2os(C4E_CONST C4eElement* C4E_RESTRICT elem,
00643 C4eArchSize bufsize, C4eArchUint8* C4E_RESTRICT buf);
00644
00645
00646
00647 #ifdef __cplusplus
00648 }
00649 #endif
00650
00651
00652 #endif
00653
00654
00655
00656
00657