libkern_crc32.c (9b3ece1c2eb92a881cb2553271e123382bfe31c1) | libkern_crc32.c (d7f27102b590ec681c189d71d42d6679dce0ee65) |
---|---|
1/* 2 * Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 */ 28 29#include <sys/param.h> 30 31#include <stdint.h> 32 33#include <atf-c.h> 34 | 1/* 2 * Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 18 unchanged lines hidden (view full) --- 27 */ 28 29#include <sys/param.h> 30 31#include <stdint.h> 32 33#include <atf-c.h> 34 |
35#if defined(__amd64__) || defined(__i386__) |
|
35extern uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); | 36extern uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); |
37#elif defined(__aarch64__) 38extern uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned); 39#else 40#error These tests are not supported on this platform 41#endif |
|
36 37ATF_TC_WITHOUT_HEAD(crc32c_basic_correctness); 38ATF_TC_BODY(crc32c_basic_correctness, tc) 39{ 40 const uint64_t inputs[] = { 41 0xf408c634b3a9142, 42 0x80539e8c7c352e2b, 43 0x62e9121db6e4d649, --- 30 unchanged lines hidden (view full) --- 74 0xfd562dc3, 75 }; 76 size_t i; 77 uint32_t act; 78 79 ATF_REQUIRE(nitems(inputs) == nitems(results)); 80 81 for (i = 0; i < nitems(inputs); i++) { | 42 43ATF_TC_WITHOUT_HEAD(crc32c_basic_correctness); 44ATF_TC_BODY(crc32c_basic_correctness, tc) 45{ 46 const uint64_t inputs[] = { 47 0xf408c634b3a9142, 48 0x80539e8c7c352e2b, 49 0x62e9121db6e4d649, --- 30 unchanged lines hidden (view full) --- 80 0xfd562dc3, 81 }; 82 size_t i; 83 uint32_t act; 84 85 ATF_REQUIRE(nitems(inputs) == nitems(results)); 86 87 for (i = 0; i < nitems(inputs); i++) { |
88#if defined(__amd64__) || defined(__i386__) |
|
82 act = sse42_crc32c(~0, (const void *)&inputs[i], 83 sizeof(inputs[0])); | 89 act = sse42_crc32c(~0, (const void *)&inputs[i], 90 sizeof(inputs[0])); |
91#else 92 act = armv8_crc32c(~0, (const void *)&inputs[i], 93 sizeof(inputs[0])); 94#endif |
|
84 ATF_REQUIRE_MSG(act == results[i], 85 "crc32c(0x%jx) = 0x%08x, got 0x%08x", (uintmax_t)inputs[i], 86 results[i], act); 87 } 88} 89 90ATF_TC_WITHOUT_HEAD(crc32c_alignment); 91ATF_TC_BODY(crc32c_alignment, tc) 92{ 93 const uint64_t input = 0xf408c634b3a9142; 94 const uint32_t result = 0x2ce33ede; 95 unsigned char buf[15]; 96 size_t i; 97 uint32_t act; 98 99 100 for (i = 1; i < 8; i++) { 101 memcpy(&buf[i], &input, sizeof(input)); 102 | 95 ATF_REQUIRE_MSG(act == results[i], 96 "crc32c(0x%jx) = 0x%08x, got 0x%08x", (uintmax_t)inputs[i], 97 results[i], act); 98 } 99} 100 101ATF_TC_WITHOUT_HEAD(crc32c_alignment); 102ATF_TC_BODY(crc32c_alignment, tc) 103{ 104 const uint64_t input = 0xf408c634b3a9142; 105 const uint32_t result = 0x2ce33ede; 106 unsigned char buf[15]; 107 size_t i; 108 uint32_t act; 109 110 111 for (i = 1; i < 8; i++) { 112 memcpy(&buf[i], &input, sizeof(input)); 113 |
114#if defined(__amd64__) || defined(__i386__) |
|
103 act = sse42_crc32c(~0, (const void *)&buf[i], sizeof(input)); | 115 act = sse42_crc32c(~0, (const void *)&buf[i], sizeof(input)); |
116#else 117 act = armv8_crc32c(~0, (const void *)&buf[i], sizeof(input)); 118#endif |
|
104 ATF_REQUIRE_MSG(act == result, 105 "crc32c(0x%jx) = 0x%08x, got 0x%08x", (uintmax_t)input, 106 result, act); 107 } 108} 109 110ATF_TC_WITHOUT_HEAD(crc32c_trailing_bytes); 111ATF_TC_BODY(crc32c_trailing_bytes, tc) 112{ 113 const unsigned char input[] = { 114 0x87, 0x54, 0x74, 0xd2, 0xb, 0x9b, 0xdd, 0xf6, 0x68, 0x37, 115 0xd4, 0x4, 0x5e, 0xa9, 0xb3 116 }; 117 const uint32_t result = 0xec638d62; 118 uint32_t act; 119 | 119 ATF_REQUIRE_MSG(act == result, 120 "crc32c(0x%jx) = 0x%08x, got 0x%08x", (uintmax_t)input, 121 result, act); 122 } 123} 124 125ATF_TC_WITHOUT_HEAD(crc32c_trailing_bytes); 126ATF_TC_BODY(crc32c_trailing_bytes, tc) 127{ 128 const unsigned char input[] = { 129 0x87, 0x54, 0x74, 0xd2, 0xb, 0x9b, 0xdd, 0xf6, 0x68, 0x37, 130 0xd4, 0x4, 0x5e, 0xa9, 0xb3 131 }; 132 const uint32_t result = 0xec638d62; 133 uint32_t act; 134 |
135#if defined(__amd64__) || defined(__i386__) |
|
120 act = sse42_crc32c(~0, input, sizeof(input)); | 136 act = sse42_crc32c(~0, input, sizeof(input)); |
137#else 138 act = armv8_crc32c(~0, input, sizeof(input)); 139#endif |
|
121 ATF_REQUIRE_MSG(act == result, "expected 0x%08x, got 0x%08x", result, 122 act); 123} 124 125ATF_TP_ADD_TCS(tp) 126{ 127 128 ATF_TP_ADD_TC(tp, crc32c_basic_correctness); 129 ATF_TP_ADD_TC(tp, crc32c_alignment); 130 ATF_TP_ADD_TC(tp, crc32c_trailing_bytes); 131 return (atf_no_error()); 132} | 140 ATF_REQUIRE_MSG(act == result, "expected 0x%08x, got 0x%08x", result, 141 act); 142} 143 144ATF_TP_ADD_TCS(tp) 145{ 146 147 ATF_TP_ADD_TC(tp, crc32c_basic_correctness); 148 ATF_TP_ADD_TC(tp, crc32c_alignment); 149 ATF_TP_ADD_TC(tp, crc32c_trailing_bytes); 150 return (atf_no_error()); 151} |