Files
ciciec2026_loongson/sdk/software/examples/fireye/D1/D1.c
2026-04-12 22:20:18 +08:00

77 lines
6.6 KiB
C

//BSP板级支持包所需全局变量
unsigned long UART_BASE = 0xbfe001e0; //UART16550的虚地址
unsigned long CONFREG_UART_BASE = 0xbfafff10; //CONFREG模拟UART的虚地址
unsigned long CONFREG_TIMER_BASE = 0xbfafe000; //CONFREG计数器的虚地址
unsigned long CONFREG_CLOCKS_PER_SEC = 100000000L; //CONFREG时钟频率
unsigned long CORE_CLOCKS_PER_SEC = 33000000L; //处理器核时钟频率
int x = 1000, y = 1000, D1_n = 492;
int D1_data0[492] = {595, 982, 328, 543, 646, 541, 484, 344, 862, 393, 378, 997, 699, 264, 128, 565, 582, 136, 768, 872, 967, 769, 979, 439, 892, 174, 779, 339, 520, 175, 931, 606, 146, 430, 661, 877, 950, 103, 563, 903, 681, 921, 924, 186, 20, 591, 953, 962, 253, 882, 141, 413, 845, 337, 465, 735, 659, 750, 821, 853, 100, 521, 16, 740, 580, 468, 562, 206, 476, 682, 68, 634, 126, 895, 947, 696, 246, 511, 38, 356, 319, 291, 519, 367, 164, 279, 330, 560, 137, 350, 564, 51, 332, 256, 657, 455, 459, 242, 537, 23, 526, 714, 10, 412, 630, 287, 410, 840, 987, 99, 98, 311, 235, 198, 588, 977, 282, 6, 841, 719, 598, 259, 207, 255, 720, 664, 766, 501, 671, 323, 937, 949, 392, 14, 739, 217, 228, 592, 957, 556, 406, 376, 94, 518, 669, 315, 223, 22, 483, 625, 780, 990, 748, 172, 33, 884, 341, 972, 426, 831, 529, 724, 787, 241, 628, 744, 461, 12, 763, 850, 973, 247, 403, 195, 790, 290, 856, 764, 331, 796, 69, 677, 754, 102, 355, 804, 738, 46, 920, 566, 795, 989, 803, 514, 742, 364, 125, 629, 889, 570, 776, 161, 24, 885, 601, 948, 822, 761, 805, 495, 326, 871, 911, 952, 651, 153, 858, 506, 913, 919, 799, 236, 737, 559, 249, 965, 729, 208, 202, 615, 833, 417, 340, 440, 834, 257, 741, 700, 122, 158, 452, 116, 215, 755, 851, 283, 276, 618, 36, 819, 133, 600, 645, 148, 583, 983, 115, 929, 313, 63, 405, 181, 534, 785, 767, 945, 351, 303, 797, 415, 930, 204, 400, 467, 727, 690, 854, 268, 789, 728, 602, 307, 976, 360, 444, 552, 144, 41, 384, 706, 905, 899, 828, 510, 694, 245, 62, 670, 425, 597, 394, 551, 607, 273, 117, 42, 839, 500, 686, 879, 986, 423, 486, 532, 745, 294, 65, 544, 916, 286, 284, 120, 383, 170, 179, 868, 818, 90, 616, 936, 823, 807, 568, 233, 447, 557, 722, 723, 297, 448, 656, 642, 266, 433, 808, 830, 280, 361, 185, 708, 293, 545, 225, 956, 567, 229, 917, 398, 673, 718, 281, 586, 60, 5, 352, 270, 149, 594, 775, 676, 458, 436, 2, 528, 451, 244, 975, 366, 162, 93, 298, 274, 810, 852, 37, 131, 826, 631, 349, 701, 784, 915, 89, 34, 814, 512, 372, 497, 316, 912, 209, 614, 231, 189, 984, 132, 407, 946, 308, 301, 166, 83, 58, 357, 914, 427, 44, 715, 434, 968, 887, 7, 505, 396, 214, 420, 674, 620, 477, 792, 760, 925, 961, 666, 991, 944, 637, 542, 698, 442, 865, 110, 730, 933, 875, 498, 783, 234, 765, 399, 88, 704, 535, 707, 18, 992, 445, 716, 310, 891, 32, 277, 824, 938, 751, 91, 391, 675, 385, 82, 842, 70, 324, 612, 558, 112, 581, 359, 752, 999, 424, 832, 782, 299, 288, 746, 438, 599, 414, 487, 201, 464};
int D1_data1[492] = {29, 951, 39, 276, 380, 861, 357, 324, 624, 363, 758, 792, 233, 752, 950, 894, 215, 23, 525, 414, 933, 547, 364, 155, 256, 953, 749, 833, 344, 792, 614, 633, 325, 744, 872, 239, 317, 77, 29, 20, 545, 601, 168, 369, 124, 760, 727, 515, 49, 7, 292, 631, 384, 262, 665, 430, 403, 304, 458, 541, 314, 998, 324, 578, 27, 607, 245, 38, 851, 874, 478, 900, 370, 175, 514, 13, 845, 717, 67, 723, 901, 828, 936, 891, 72, 952, 762, 536, 985, 488, 229, 81, 909, 613, 840, 66, 901, 79, 813, 59, 212, 502, 985, 317, 112, 161, 941, 880, 150, 599, 730, 378, 847, 367, 901, 155, 982, 340, 97, 957, 78, 138, 359, 29, 950, 578, 626, 548, 80, 703, 674, 80, 869, 941, 324, 893, 76, 263, 836, 365, 453, 270, 507, 530, 865, 982, 493, 868, 148, 869, 675, 470, 440, 512, 797, 929, 897, 224, 619, 666, 251, 485, 707, 680, 281, 990, 435, 675, 189, 463, 743, 489, 662, 223, 155, 25, 476, 862, 870, 284, 445, 191, 297, 181, 900, 288, 249, 371, 533, 929, 159, 30, 89, 986, 33, 547, 178, 949, 964, 130, 700, 840, 124, 242, 376, 879, 746, 295, 450, 784, 844, 753, 38, 434, 403, 439, 598, 713, 480, 589, 742, 234, 650, 922, 3, 771, 16, 498, 371, 956, 747, 848, 30, 769, 483, 810, 683, 600, 981, 168, 127, 325, 324, 255, 446, 33, 281, 786, 896, 383, 387, 823, 302, 314, 437, 102, 629, 272, 478, 419, 375, 549, 425, 27, 410, 532, 44, 988, 198, 187, 504, 37, 837, 257, 338, 660, 124, 978, 813, 52, 521, 329, 388, 855, 729, 117, 314, 769, 127, 191, 292, 21, 895, 37, 718, 250, 514, 779, 326, 577, 306, 757, 34, 363, 786, 809, 153, 70, 714, 610, 575, 213, 611, 20, 958, 615, 985, 251, 181, 7, 569, 307, 91, 996, 93, 105, 143, 944, 864, 546, 444, 453, 318, 514, 383, 546, 81, 128, 780, 35, 521, 714, 288, 14, 622, 621, 701, 445, 187, 246, 593, 674, 331, 38, 120, 898, 366, 429, 291, 221, 553, 59, 326, 558, 565, 393, 991, 549, 232, 80, 935, 330, 491, 632, 478, 58, 396, 183, 205, 769, 236, 537, 92, 516, 379, 90, 796, 248, 418, 230, 368, 666, 608, 993, 219, 700, 456, 294, 917, 482, 613, 662, 390, 2, 947, 11, 81, 607, 898, 855, 18, 857, 310, 811, 666, 940, 359, 199, 148, 476, 315, 890, 310, 968, 979, 174, 895, 632, 597, 759, 255, 1, 133, 763, 788, 136, 256, 335, 325, 766, 901, 280, 254, 688, 731, 793, 996, 288, 80, 80, 842, 584, 951, 600, 818, 323, 303, 303, 318, 807, 47, 864, 63, 140, 450, 231, 905, 200, 247, 725, 4, 714, 122, 298, 60, 547, 433, 328, 666, 606, 143, 643, 689, 716, 425, 737, 594, 255, 243, 931, 537, 358};
#define LOOP 2
#include <stdio.h>
#include <string.h>
#define MAXN 10000
int in[MAXN] = {1}, out[MAXN] = {1};
int mn[MAXN] = {1}, mx [MAXN] = {1};
int D1_max(int a, int b) { return a > b ? a : b; }
int D1_min(int a, int b) { return a < b ? a : b; }
int main() {
int ans;
for (int l = 0; l < LOOP; l++) {
memset(mn, -1, (D1_max(x, y) + 1) * sizeof(int));
memset(mx, -1, (D1_max(x, y) + 1) * sizeof(int));
memset(in, 0, (D1_max(x, y) + 1) * sizeof(int));
memset(out, 0, (D1_max(x, y) + 1) * sizeof(int));
int a, b;
for (int i = 0; i < D1_n; i++) {
a = D1_data0[i];
b = D1_data1[i];
if (mn[a] == -1)
mn[a] = b;
else
mn[a] = D1_min(mn[a], b);
mx[a] = D1_max(mx[a], b);
}
int reduce = 0;
int down = 0;
int sum = 0;
for (int i = 0; i < y + 1; i++) {
if (mx[i] != -1){
in[mx[i]]++;
out[mn[i]]++;
sum += mn[i];
down++;
}
}
ans = 0x7fffffff;
int up = 0, upsum = 0;
for (int p = y + 1; p >= 0; p--){
if (in[p] > 0){
up += in[p];
upsum += in[p] * p;
}
if (out[p] > 0){
down -= out[p];
sum -= out[p] * p;
}
int df = 2 * ((upsum - up * p) + (down * p - sum));
ans = D1_min(ans, df);
}
}
printf("%d\n", ans + x - 1);
return (ans + x - 1 == 253649) ? 0 : 1;
}