简体   繁体   中英

How can I make sure there is no floating point arithmetic in a C code (Visual Studio 2013 express + WDK 8.1, WDM kernel driver)?

Some years ago I came across a modified moufiltr driver (made by Povohat), which allows the user to set a customized mouse acceleration. This driver used floating point arithmetic. I found a mouclass sample driver in the WDK7 samples, based on povohat's moufiltr driver I have modified this sample to include tunable acceleration (equation from Quake 3 cl_input.c), but with upscaled integers instead of doubles and so without the need of KeSaveFloatingPointState. The point of this is to have something for Windows XP too.

Is it safe to assume there is no floating point arithmetic used if there is nothing but type LONGLONG variables are used in the calculations (+,/,*,%)?

Even if your code is free of floating point literals, floating point variables, and floating point casts, it's not safe to assume that it's free of floating point operations at the compiled machine code level. Usually, with optimizations turned off, the compiled code is basically a direct translation of the source code, in this case your chances are higher that if you have no floating point mechanics in your source code then neither you will in the compiled code. However, compilers usually have full access to the instruction set of the target architecture, and with optimizations turned on, they will heavily modify the final compiled output according to the optimization criteria (usually speed and/or size). In this case, if some (or all) floating point instructions where deemed by the compiler as necessary, then they will be present in the compiled machine code even if your source code is free of them. If your compiler doesn't support restricting what machine code (assembler) instructions it can use, and VS 2013 Express doesn't, then the only way to find out is to decompile your compiled code and look for floating point instructions yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM